Commit ded69662 authored by Andreas Jung's avatar Andreas Jung

- Launchpad #267834: proper separation of HTTP header fields

  using CRLF as requested by RFC 2616.
parent fa0e693a
...@@ -207,6 +207,9 @@ Zope Changes ...@@ -207,6 +207,9 @@ Zope Changes
Bugs Fixed Bugs Fixed
- Launchpad #267834: proper separation of HTTP header fields
using CRLF as requested by RFC 2616.
- Launchpad #267545: DateTime(DateTime()) now preserves the - Launchpad #267545: DateTime(DateTime()) now preserves the
correct hour correct hour
......
...@@ -102,7 +102,7 @@ class TestRequestRange(unittest.TestCase): ...@@ -102,7 +102,7 @@ class TestRequestRange(unittest.TestCase):
# Chop off any printed headers (only when response.write was used) # Chop off any printed headers (only when response.write was used)
if body: if body:
body = string.split(body, '\n\n', 1)[1] body = string.split(body, '\r\n\r\n', 1)[1]
return body + rv return body + rv
......
...@@ -108,7 +108,7 @@ class Functional(sandbox.Sandboxed): ...@@ -108,7 +108,7 @@ class Functional(sandbox.Sandboxed):
class ResponseWrapper: class ResponseWrapper:
'''Decorates a response object with additional introspective methods.''' '''Decorates a response object with additional introspective methods.'''
_bodyre = re.compile('^$^\n(.*)', re.MULTILINE | re.DOTALL) _bodyre = re.compile('\r\n\r\n(.*)', re.MULTILINE | re.DOTALL)
def __init__(self, response, outstream, path): def __init__(self, response, outstream, path):
self._response = response self._response = response
......
...@@ -51,7 +51,7 @@ class MakerequestTests(unittest.TestCase): ...@@ -51,7 +51,7 @@ class MakerequestTests(unittest.TestCase):
item.REQUEST.RESPONSE.write('aaa') item.REQUEST.RESPONSE.write('aaa')
out.seek(0) out.seek(0)
written = out.read() written = out.read()
self.failUnless(written.startswith('Status: 200 OK\n')) self.failUnless(written.startswith('Status: 200 OK\r\n'))
self.failUnless(written.endswith('\naaa')) self.failUnless(written.endswith('\naaa'))
def test_environ(self): def test_environ(self):
......
...@@ -254,7 +254,7 @@ class HTTPResponse(BaseResponse): ...@@ -254,7 +254,7 @@ class HTTPResponse(BaseResponse):
key = name.lower() key = name.lower()
if accumulate_header(key): if accumulate_header(key):
self.accumulated_headers = ( self.accumulated_headers = (
"%s%s: %s\n" % (self.accumulated_headers, name, value)) "%s%s: %s\r\n" % (self.accumulated_headers, name, value))
return return
name = literal and name or key name = literal and name or key
self.headers[name] = value self.headers[name] = value
...@@ -278,7 +278,7 @@ class HTTPResponse(BaseResponse): ...@@ -278,7 +278,7 @@ class HTTPResponse(BaseResponse):
name = str(name) name = str(name)
value = str(value) value = str(value)
self.accumulated_headers = ( self.accumulated_headers = (
"%s%s: %s\n" % (self.accumulated_headers, name, value)) "%s%s: %s\r\n" % (self.accumulated_headers, name, value))
__setitem__ = setHeader __setitem__ = setHeader
...@@ -591,7 +591,7 @@ class HTTPResponse(BaseResponse): ...@@ -591,7 +591,7 @@ class HTTPResponse(BaseResponse):
headers = self.headers headers = self.headers
if headers.has_key(name): if headers.has_key(name):
h = headers[name] h = headers[name]
h = "%s%s\n\t%s" % (h,delimiter,value) h = "%s%s\r\n\t%s" % (h,delimiter,value)
else: else:
h = value h = value
self.setHeader(name,h) self.setHeader(name,h)
...@@ -893,7 +893,7 @@ class HTTPResponse(BaseResponse): ...@@ -893,7 +893,7 @@ class HTTPResponse(BaseResponse):
if self.cookies: if self.cookies:
headersl = headersl+self._cookie_list() headersl = headersl+self._cookie_list()
headersl[len(headersl):] = [self.accumulated_headers, body] headersl[len(headersl):] = [self.accumulated_headers, body]
return '\n'.join(headersl) return '\r\n'.join(headersl)
def write(self,data): def write(self,data):
"""\ """\
......
...@@ -72,10 +72,10 @@ class HTTPResponseTests(unittest.TestCase): ...@@ -72,10 +72,10 @@ class HTTPResponseTests(unittest.TestCase):
response = self._makeOne() response = self._makeOne()
response.setHeader('foo', 'bar') response.setHeader('foo', 'bar')
response.appendHeader('foo', 'foo') response.appendHeader('foo', 'foo')
self.assertEqual(response.headers.get('foo'), 'bar,\n\tfoo') self.assertEqual(response.headers.get('foo'), 'bar,\r\n\tfoo')
response.setHeader('xxx', 'bar') response.setHeader('xxx', 'bar')
response.appendHeader('XXX', 'foo') response.appendHeader('XXX', 'foo')
self.assertEqual(response.headers.get('xxx'), 'bar,\n\tfoo') self.assertEqual(response.headers.get('xxx'), 'bar,\r\n\tfoo')
def test_setHeader(self): def test_setHeader(self):
response = self._makeOne() response = self._makeOne()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment