Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
nghttp2
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
nghttp2
Commits
9d66fc4b
Commit
9d66fc4b
authored
Aug 24, 2012
by
Tatsuhiro Tsujikawa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
python: wrap socket in overridden process_request.
parent
e2083055
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
61 additions
and
60 deletions
+61
-60
python/spdylay.pyx
python/spdylay.pyx
+61
-60
No files found.
python/spdylay.pyx
View file @
9d66fc4b
...
...
@@ -1235,7 +1235,7 @@ try:
def
send_cb
(
self
,
session
,
data
):
return
self
.
sslsock
.
send
(
data
)
return
self
.
request
.
send
(
data
)
def
read_cb
(
self
,
session
,
stream_id
,
length
,
read_ctrl
,
source
):
data
=
source
.
read
(
length
)
...
...
@@ -1277,65 +1277,54 @@ try:
def
handle
(
self
):
self
.
request
.
setsockopt
(
socket
.
IPPROTO_TCP
,
socket
.
TCP_NODELAY
,
True
)
# TODO We need to call handshake manually because 3.3.0b2
# crashes if do_handshake_on_connect=True
self
.
sslsock
=
self
.
server
.
ctx
.
wrap_socket
(
\
self
.
request
,
server_side
=
True
,
do_handshake_on_connect
=
False
)
self
.
sslsock
.
setblocking
(
False
)
while
True
:
try
:
self
.
sslsock
.
do_handshake
()
break
except
ssl
.
SSLWantReadError
as
e
:
select
.
select
([
self
.
sslsock
],
[],
[])
except
ssl
.
SSLWantWriteError
as
e
:
select
.
select
([],
[
self
.
sslsock
],
[])
version
=
npn_get_version
(
self
.
sslsock
.
selected_npn_protocol
())
if
version
==
0
:
return
self
.
ssctrl
=
SessionCtrl
()
self
.
session
=
Session
(
\
SERVER
,
version
,
send_cb
=
self
.
send_cb
,
on_ctrl_recv_cb
=
self
.
on_ctrl_recv_cb
,
on_data_chunk_recv_cb
=
self
.
on_data_chunk_recv_cb
,
on_stream_close_cb
=
self
.
on_stream_close_cb
,
on_request_recv_cb
=
self
.
on_request_recv_cb
)
self
.
session
.
submit_settings
(
\
FLAG_SETTINGS_NONE
,
[(
SETTINGS_MAX_CONCURRENT_STREAMS
,
ID_FLAG_SETTINGS_NONE
,
100
)]
)
while
self
.
session
.
want_read
()
or
self
.
session
.
want_write
():
want_read
=
want_write
=
False
try
:
data
=
self
.
sslsock
.
recv
(
4096
)
if
data
:
self
.
session
.
recv
(
data
)
else
:
break
except
ssl
.
SSLWantReadError
:
want_read
=
True
except
ssl
.
SSLWantWriteError
:
want_write
=
True
try
:
self
.
session
.
send
()
except
ssl
.
SSLWantReadError
:
want_read
=
True
except
ssl
.
SSLWantWriteError
:
want_write
=
True
if
want_read
or
want_write
:
select
.
select
([
self
.
sslsock
]
if
want_read
else
[],
[
self
.
sslsock
]
if
want_write
else
[],
[])
try
:
self
.
request
.
do_handshake
()
self
.
request
.
setblocking
(
False
)
version
=
npn_get_version
(
self
.
request
.
selected_npn_protocol
())
if
version
==
0
:
return
self
.
ssctrl
=
SessionCtrl
()
self
.
session
=
Session
(
\
SERVER
,
version
,
send_cb
=
self
.
send_cb
,
on_ctrl_recv_cb
=
self
.
on_ctrl_recv_cb
,
on_data_chunk_recv_cb
=
self
.
on_data_chunk_recv_cb
,
on_stream_close_cb
=
self
.
on_stream_close_cb
,
on_request_recv_cb
=
self
.
on_request_recv_cb
)
self
.
session
.
submit_settings
(
\
FLAG_SETTINGS_NONE
,
[(
SETTINGS_MAX_CONCURRENT_STREAMS
,
ID_FLAG_SETTINGS_NONE
,
100
)]
)
while
self
.
session
.
want_read
()
or
self
.
session
.
want_write
():
want_read
=
want_write
=
False
try
:
data
=
self
.
request
.
recv
(
4096
)
if
data
:
self
.
session
.
recv
(
data
)
else
:
break
except
ssl
.
SSLWantReadError
:
want_read
=
True
except
ssl
.
SSLWantWriteError
:
want_write
=
True
try
:
self
.
session
.
send
()
except
ssl
.
SSLWantReadError
:
want_read
=
True
except
ssl
.
SSLWantWriteError
:
want_write
=
True
if
want_read
or
want_write
:
select
.
select
([
self
.
request
]
if
want_read
else
[],
[
self
.
request
]
if
want_write
else
[],
[])
finally
:
self
.
request
.
setblocking
(
True
)
# The following methods and attributes are copied from
# Lib/http/server.py of cpython source code
...
...
@@ -1463,6 +1452,18 @@ try:
server_thread
.
daemon
=
daemon
server_thread
.
start
()
def
process_request
(
self
,
request
,
client_address
):
# ThreadingMixIn.process_request() dispatches request and
# client_address to separate thread. To cleanly shutdown
# SSL/TLS wrapped socket, we wrap socket here.
# SSL/TLS handshake is postponed to each thread.
request
=
self
.
ctx
.
wrap_socket
(
\
request
,
server_side
=
True
,
do_handshake_on_connect
=
False
)
socketserver
.
ThreadingMixIn
.
process_request
(
self
,
request
,
client_address
)
except
ImportError
:
# No server for 2.x because they lack TLS NPN.
pass
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