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
77a21373
Commit
77a21373
authored
Jun 18, 2018
by
Jason Madden
Committed by
GitHub
Jun 18, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1240 from gevent/issue1233
Use a buffer to generate HTTP chunks.
parents
c1b473f0
45a16fa0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
9 deletions
+25
-9
CHANGES.rst
CHANGES.rst
+3
-0
src/gevent/pywsgi.py
src/gevent/pywsgi.py
+22
-9
No files found.
CHANGES.rst
View file @
77a21373
...
...
@@ -12,6 +12,9 @@
condition that is known to lead to RecursionError. This may produce
false negatives, but should reduce or eliminate false positives.
- Based on measurements and discussion in :issue:`1233`, adjust the
way :mod:`gevent.pywsgi` generates HTTP chunks. This is intended to
reduce network overhead, especially for smaller chunk sizes.
1.3.3 (2018-06-08)
==================
...
...
src/gevent/pywsgi.py
View file @
77a21373
...
...
@@ -708,7 +708,9 @@ class WSGIHandler(object):
raise
self
.
response_length
+=
len
(
data
)
def
_write
(
self
,
data
):
def
_write
(
self
,
data
,
_PY34_EXACTLY
=
(
sys
.
version_info
[:
2
]
==
(
3
,
4
)),
_bytearray
=
bytearray
):
if
not
data
:
# The application/middleware are allowed to yield
# empty bytestrings.
...
...
@@ -716,14 +718,25 @@ class WSGIHandler(object):
if
self
.
response_use_chunked
:
## Write the chunked encoding
header
=
(
"%x
\
r
\
n
"
%
len
(
data
)).
encode
(
'ascii'
)
# socket.sendall will slice these small strings, as [0:],
# but that's special cased to return the original string.
# They're small enough we probably expect them to go down to the network
# buffers in one go anyway.
self
.
_sendall
(
header
)
self
.
_sendall
(
data
)
self
.
_sendall
(
b'
\
r
\
n
'
)
# trailer
# header
if
_PY34_EXACTLY
:
# This is the only version we support that doesn't
# allow % to be used with bytes. Passing a bytestring
# directly in to bytearray() is faster than passing a
# (unicode) str with encoding, which naturally is faster still
# than encoding first. Interestingly, byte formatting on Python 3
# is faster than str formatting.
header_str
=
'%x
\
r
\
n
'
%
len
(
data
)
towrite
=
_bytearray
(
header_str
,
'ascii'
)
else
:
header_str
=
b'%x
\
r
\
n
'
%
len
(
data
)
towrite
=
_bytearray
(
header_str
)
# data
towrite
.
extend
(
data
)
# trailer
towrite
.
extend
(
b'
\
r
\
n
'
)
self
.
_sendall
(
towrite
)
else
:
self
.
_sendall
(
data
)
...
...
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