Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
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
Zope
Commits
edb155f4
Commit
edb155f4
authored
Oct 27, 2008
by
Tres Seaver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Actually land the CRLF response header fix.
parent
ad645a67
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
9 deletions
+46
-9
lib/python/ZPublisher/HTTPResponse.py
lib/python/ZPublisher/HTTPResponse.py
+11
-9
lib/python/ZPublisher/tests/testHTTPResponse.py
lib/python/ZPublisher/tests/testHTTPResponse.py
+35
-0
No files found.
lib/python/ZPublisher/HTTPResponse.py
View file @
edb155f4
...
...
@@ -122,6 +122,10 @@ otherTypes = os.environ.get('DONT_GZIP_MAJOR_MIME_TYPES','').lower()
if
otherTypes
:
uncompressableMimeMajorTypes
+=
tuple
(
otherTypes
.
split
(
','
))
_CRLF
=
re
.
compile
(
r'\r[\n]?'
)
def
_scrubHeader
(
name
,
value
):
return
''
.
join
(
_CRLF
.
split
(
str
(
name
))),
''
.
join
(
_CRLF
.
split
(
str
(
value
)))
class
HTTPResponse
(
BaseResponse
):
"""
\
...
...
@@ -242,15 +246,14 @@ class HTTPResponse(BaseResponse):
if
lock
:
self
.
_locked_status
=
1
def
setHeader
(
self
,
name
,
value
,
literal
=
0
):
def
setHeader
(
self
,
name
,
value
,
literal
=
0
,
scrubbed
=
False
):
'''
\
Sets an HTTP return header "name" with value "value", clearing
the previous value set for the header, if one exists. If the
literal flag is true, the case of the header name is preserved,
otherwise the header name will be lowercased.'''
name
=
str
(
name
)
value
=
str
(
value
)
if
not
scrubbed
:
name
,
value
=
_scrubHeader
(
name
,
value
)
key
=
name
.
lower
()
if
accumulate_header
(
key
):
self
.
accumulated_headers
=
(
...
...
@@ -275,8 +278,7 @@ class HTTPResponse(BaseResponse):
'''
\
Set a new HTTP return header with the given value, while retaining
any previously set headers with the same name.'''
name
=
str
(
name
)
value
=
str
(
value
)
name
,
value
=
_scrubHeader
(
name
,
value
)
self
.
accumulated_headers
=
(
"%s%s: %s
\
r
\
n
"
%
(
self
.
accumulated_headers
,
name
,
value
))
...
...
@@ -585,8 +587,8 @@ class HTTPResponse(BaseResponse):
Sets an HTTP return header "name" with value "value",
appending it following a comma if there was a previous value
set for the header. '''
name
=
str
(
name
).
lower
(
)
value
=
str
(
value
)
name
,
value
=
_scrubHeader
(
name
,
value
)
name
=
name
.
lower
(
)
headers
=
self
.
headers
if
headers
.
has_key
(
name
):
...
...
@@ -594,7 +596,7 @@ class HTTPResponse(BaseResponse):
h
=
"%s%s
\
r
\
n
\
t
%s"
%
(
h
,
delimiter
,
value
)
else
:
h
=
value
self
.
setHeader
(
name
,
h
)
self
.
setHeader
(
name
,
h
,
scrubbed
=
True
)
def
isHTML
(
self
,
s
):
s
=
s
.
lstrip
()
...
...
lib/python/ZPublisher/tests/testHTTPResponse.py
View file @
edb155f4
...
...
@@ -145,6 +145,41 @@ class HTTPResponseTests(unittest.TestCase):
response
=
self
.
_makeOne
(
body
=
xml
,
headers
=
{
'content-type'
:
'text/xml; charset=iso-8859-15'
})
self
.
assertEqual
(
xml
==
response
.
body
,
True
)
def
test_addHeader_drops_CRLF
(
self
):
# RFC2616 disallows CRLF in a header value.
response
=
self
.
_makeOne
()
response
.
addHeader
(
'Location'
,
'http://www.ietf.org/rfc/
\
r
\
n
rfc2616.txt'
)
self
.
assertEqual
(
response
.
accumulated_headers
,
'Location: http://www.ietf.org/rfc/rfc2616.txt
\
r
\
n
'
)
def
test_appendHeader_drops_CRLF
(
self
):
# RFC2616 disallows CRLF in a header value.
response
=
self
.
_makeOne
()
response
.
appendHeader
(
'Location'
,
'http://www.ietf.org/rfc/
\
r
\
n
rfc2616.txt'
)
self
.
assertEqual
(
response
.
headers
[
'location'
],
'http://www.ietf.org/rfc/rfc2616.txt'
)
def
test_setHeader_drops_CRLF
(
self
):
# RFC2616 disallows CRLF in a header value.
response
=
self
.
_makeOne
()
response
.
setHeader
(
'Location'
,
'http://www.ietf.org/rfc/
\
r
\
n
rfc2616.txt'
)
self
.
assertEqual
(
response
.
headers
[
'location'
],
'http://www.ietf.org/rfc/rfc2616.txt'
)
def
test_setHeader_drops_CRLF_when_accumulating
(
self
):
# RFC2616 disallows CRLF in a header value.
response
=
self
.
_makeOne
()
response
.
setHeader
(
'Set-Cookie'
,
'allowed="OK"'
)
response
.
setHeader
(
'Set-Cookie'
,
'violation="http://www.ietf.org/rfc/
\
r
\
n
rfc2616.txt"'
)
self
.
assertEqual
(
response
.
accumulated_headers
,
'Set-Cookie: allowed="OK"
\
r
\
n
'
+
'Set-Cookie: '
'violation="http://www.ietf.org/rfc/rfc2616.txt"
\
r
\
n
'
)
def
test_suite
():
suite
=
unittest
.
TestSuite
()
...
...
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