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
c5597248
Commit
c5597248
authored
Aug 29, 2011
by
Denis Bilenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pywsgi: extract finalize_headers() method; do not calculate response_headers_list if not necessary
parent
fe8a2f8e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
24 deletions
+23
-24
gevent/pywsgi.py
gevent/pywsgi.py
+23
-24
No files found.
gevent/pywsgi.py
View file @
c5597248
...
...
@@ -329,40 +329,40 @@ class WSGIHandler(object):
return
True
# read more requests
def
finalize_headers
(
self
):
response_headers_list
=
[
x
[
0
]
for
x
in
self
.
response_headers
]
if
'Date'
not
in
response_headers_list
:
self
.
response_headers
.
append
((
'Date'
,
format_date_time
(
time
.
time
())))
if
self
.
request_version
==
'HTTP/1.0'
and
'Connection'
not
in
response_headers_list
:
self
.
response_headers
.
append
((
'Connection'
,
'close'
))
self
.
close_connection
=
True
elif
(
'Connection'
,
'close'
)
in
self
.
response_headers
:
self
.
close_connection
=
True
if
self
.
code
not
in
[
204
,
304
]:
# the reply will include message-body; make sure we have either Content-Length or chunked
if
'Content-Length'
not
in
response_headers_list
:
if
hasattr
(
self
.
result
,
'__len__'
):
self
.
response_headers
.
append
((
'Content-Length'
,
str
(
sum
(
len
(
chunk
)
for
chunk
in
self
.
result
))))
else
:
if
self
.
request_version
!=
'HTTP/1.0'
:
self
.
response_use_chunked
=
True
self
.
response_headers
.
append
((
'Transfer-Encoding'
,
'chunked'
))
def
write
(
self
,
data
):
towrite
=
[]
if
not
self
.
status
:
raise
AssertionError
(
"The application did not call start_response()"
)
if
not
self
.
headers_sent
:
if
'Date'
not
in
self
.
response_headers_list
:
self
.
response_headers
.
append
((
'Date'
,
format_date_time
(
time
.
time
())))
self
.
response_headers_list
.
append
(
'Date'
)
if
self
.
request_version
==
'HTTP/1.0'
and
'Connection'
not
in
self
.
response_headers_list
:
self
.
response_headers
.
append
((
'Connection'
,
'close'
))
self
.
response_headers_list
.
append
(
'Connection'
)
self
.
close_connection
=
True
elif
(
'Connection'
,
'close'
)
in
self
.
response_headers
:
self
.
close_connection
=
True
if
self
.
code
not
in
[
204
,
304
]:
# the reply will include message-body; make sure we have either Content-Length or chunked
if
'Content-Length'
not
in
self
.
response_headers_list
:
if
hasattr
(
self
.
result
,
'__len__'
):
self
.
response_headers
.
append
((
'Content-Length'
,
str
(
sum
(
len
(
chunk
)
for
chunk
in
self
.
result
))))
self
.
response_headers_list
.
append
(
'Content-Length'
)
else
:
if
self
.
request_version
!=
'HTTP/1.0'
:
self
.
response_use_chunked
=
True
self
.
response_headers
.
append
((
'Transfer-Encoding'
,
'chunked'
))
self
.
response_headers_list
.
append
(
'Transfer-Encoding'
)
self
.
headers_sent
=
True
self
.
finalize_headers
()
towrite
.
append
(
'%s %s
\
r
\
n
'
%
(
self
.
request_version
,
self
.
status
))
for
header
in
self
.
response_headers
:
towrite
.
append
(
'%s: %s
\
r
\
n
'
%
header
)
towrite
.
append
(
'
\
r
\
n
'
)
self
.
headers_sent
=
True
if
data
:
if
self
.
response_use_chunked
:
...
...
@@ -387,7 +387,6 @@ class WSGIHandler(object):
self
.
code
=
int
(
status
.
split
(
' '
,
1
)[
0
])
self
.
status
=
status
self
.
response_headers
=
[(
'-'
.
join
([
x
.
capitalize
()
for
x
in
key
.
split
(
'-'
)]),
value
)
for
key
,
value
in
headers
]
self
.
response_headers_list
=
[
x
[
0
]
for
x
in
self
.
response_headers
]
return
self
.
write
def
log_request
(
self
):
...
...
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