Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gevent
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gevent
Commits
4bead9db
Commit
4bead9db
authored
Dec 08, 2016
by
Arcadiy Ivanov
Committed by
Jason Madden
Dec 08, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add SSLContext to StreamServer et al
fixes #901
parent
3ab69f26
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
5 deletions
+31
-5
src/gevent/server.py
src/gevent/server.py
+20
-5
src/greentest/test__pywsgi.py
src/greentest/test__pywsgi.py
+11
-0
No files found.
src/gevent/server.py
View file @
4bead9db
...
@@ -20,8 +20,18 @@ class StreamServer(BaseServer):
...
@@ -20,8 +20,18 @@ class StreamServer(BaseServer):
"""A generic TCP server. Accepts connections on a listening socket and spawns user-provided *handle*
"""A generic TCP server. Accepts connections on a listening socket and spawns user-provided *handle*
for each connection with 2 arguments: the client socket and the client address.
for each connection with 2 arguments: the client socket and the client address.
If any of the following keyword arguments are present, then the server assumes SSL mode and uses these arguments
Server can assume an SSL mode via either direct client socket wrapper initialization or socket wrapping via an
to create an SSL wrapper for the client socket before passing it to *handle*:
:class:`SSLContext`.
If *ssl_context* keyword argument is present, it should contain an :class:`SSLContext`. The following keyword
arguments may be used SSLContext mode (subject to Python API version):
- server_hostname
- suppress_ragged_eofs
- do_handshake_on_connect
Otherwise, if any of the following keyword arguments are present, then the server assumes SSL mode and uses these
arguments to create an SSL wrapper for the client socket before passing it to *handle*:
- keyfile
- keyfile
- certfile
- certfile
...
@@ -51,9 +61,14 @@ class StreamServer(BaseServer):
...
@@ -51,9 +61,14 @@ class StreamServer(BaseServer):
try
:
try
:
if
ssl_args
:
if
ssl_args
:
ssl_args
.
setdefault
(
'server_side'
,
True
)
ssl_args
.
setdefault
(
'server_side'
,
True
)
from
gevent.ssl
import
wrap_socket
if
'ssl_context'
in
ssl_args
:
self
.
wrap_socket
=
wrap_socket
ssl_context
=
ssl_args
.
pop
(
'ssl_context'
)
self
.
ssl_args
=
ssl_args
self
.
wrap_socket
=
ssl_context
.
wrap_socket
self
.
ssl_args
=
ssl_args
else
:
from
gevent.ssl
import
wrap_socket
self
.
wrap_socket
=
wrap_socket
self
.
ssl_args
=
ssl_args
else
:
else
:
self
.
ssl_args
=
None
self
.
ssl_args
=
None
if
backlog
is
not
None
:
if
backlog
is
not
None
:
...
...
src/greentest/test__pywsgi.py
View file @
4bead9db
...
@@ -19,7 +19,9 @@
...
@@ -19,7 +19,9 @@
# THE SOFTWARE.
# THE SOFTWARE.
# pylint: disable=too-many-lines,unused-argument
# pylint: disable=too-many-lines,unused-argument
from
__future__
import
print_function
from
__future__
import
print_function
from
gevent
import
monkey
from
gevent
import
monkey
monkey
.
patch_all
(
thread
=
False
)
monkey
.
patch_all
(
thread
=
False
)
try
:
try
:
...
@@ -740,6 +742,13 @@ class HttpsTestCase(TestCase):
...
@@ -740,6 +742,13 @@ class HttpsTestCase(TestCase):
return
[
environ
[
'wsgi.input'
].
read
(
10
)]
return
[
environ
[
'wsgi.input'
].
read
(
10
)]
class
HttpsSslContextTestCase
(
HttpsTestCase
):
def
init_server
(
self
,
application
):
from
ssl
import
create_default_context
context
=
create_default_context
()
context
.
load_cert_chain
(
certfile
=
self
.
certfile
,
keyfile
=
self
.
keyfile
)
self
.
server
=
pywsgi
.
WSGIServer
((
'127.0.0.1'
,
0
),
application
,
ssl_context
=
context
)
class
TestHttps
(
HttpsTestCase
):
class
TestHttps
(
HttpsTestCase
):
if
hasattr
(
socket
,
'ssl'
):
if
hasattr
(
socket
,
'ssl'
):
...
@@ -752,6 +761,8 @@ class TestHttps(HttpsTestCase):
...
@@ -752,6 +761,8 @@ class TestHttps(HttpsTestCase):
result
=
self
.
urlopen
()
result
=
self
.
urlopen
()
self
.
assertEquals
(
result
.
body
,
''
)
self
.
assertEquals
(
result
.
body
,
''
)
class
TestHttpsWithContext
(
HttpsSslContextTestCase
,
TestHttps
):
pass
class
TestInternational
(
TestCase
):
class
TestInternational
(
TestCase
):
validator
=
None
# wsgiref.validate.IteratorWrapper([]) does not have __len__
validator
=
None
# wsgiref.validate.IteratorWrapper([]) does not have __len__
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment