Commit 97d1453e authored by Florent Guillaume's avatar Florent Guillaume

Merge from Zope-2_6-branch:

Ensured that all HTTP headers are sent as normal strings and not Unicode.
parent f5c6b791
...@@ -164,9 +164,9 @@ class TestRequestRange(unittest.TestCase): ...@@ -164,9 +164,9 @@ class TestRequestRange(unittest.TestCase):
self.failUnless(content_range == expect_content_range, self.failUnless(content_range == expect_content_range,
'Received incorrect Content-Range header. Expected %s, got %s' % ( 'Received incorrect Content-Range header. Expected %s, got %s' % (
`expect_content_range`, `content_range`)) `expect_content_range`, `content_range`))
self.failIf(rsp.getHeader('content-length') != len(body), self.failIf(rsp.getHeader('content-length') != str(len(body)),
'Incorrect Content-Length is set! Expected %d, got %d.' % ( 'Incorrect Content-Length is set! Expected %s, got %s.' % (
rsp.getHeader('content-length'), len(body))) str(len(body)), rsp.getHeader('content-length')))
self.failUnless(body == self.data[start:end], self.failUnless(body == self.data[start:end],
'Incorrect range returned, expected %s, got %s' % ( 'Incorrect range returned, expected %s, got %s' % (
...@@ -196,9 +196,9 @@ class TestRequestRange(unittest.TestCase): ...@@ -196,9 +196,9 @@ class TestRequestRange(unittest.TestCase):
"Incorrect Content-Type set. Expected 'multipart/%sbyteranges', " "Incorrect Content-Type set. Expected 'multipart/%sbyteranges', "
"got %s" % (draftprefix, ct)) "got %s" % (draftprefix, ct))
if rsp.getHeader('content-length'): if rsp.getHeader('content-length'):
self.failIf(rsp.getHeader('content-length') != len(body), self.failIf(rsp.getHeader('content-length') != str(len(body)),
'Incorrect Content-Length is set! Expected %d, got %d.' % ( 'Incorrect Content-Length is set! Expected %s, got %s.' % (
len(body), rsp.getHeader('content-length'))) str(len(body)), rsp.getHeader('content-length')))
# Decode the multipart message # Decode the multipart message
bodyfile = cStringIO.StringIO('Content-Type: %s\n\n%s' % ( bodyfile = cStringIO.StringIO('Content-Type: %s\n\n%s' % (
......
...@@ -12,8 +12,8 @@ ...@@ -12,8 +12,8 @@
############################################################################## ##############################################################################
'''CGI Response Output formatter '''CGI Response Output formatter
$Id: HTTPResponse.py,v 1.71 2002/12/17 00:38:17 andym Exp $''' $Id: HTTPResponse.py,v 1.72 2002/12/22 18:31:46 efge Exp $'''
__version__ = '$Revision: 1.71 $'[11:-2] __version__ = '$Revision: 1.72 $'[11:-2]
import types, os, sys, re import types, os, sys, re
import zlib, struct import zlib, struct
...@@ -233,6 +233,8 @@ class HTTPResponse(BaseResponse): ...@@ -233,6 +233,8 @@ class HTTPResponse(BaseResponse):
literal flag is true, the case of the header name is preserved, literal flag is true, the case of the header name is preserved,
otherwise word-capitalization will be performed on the header otherwise word-capitalization will be performed on the header
name on output.''' name on output.'''
name = str(name)
value = str(value)
key = name.lower() key = name.lower()
if accumulate_header(key): if accumulate_header(key):
self.accumulated_headers = ( self.accumulated_headers = (
...@@ -245,6 +247,8 @@ class HTTPResponse(BaseResponse): ...@@ -245,6 +247,8 @@ class HTTPResponse(BaseResponse):
'''\ '''\
Set a new HTTP return header with the given value, while retaining Set a new HTTP return header with the given value, while retaining
any previously set headers with the same name.''' any previously set headers with the same name.'''
name = str(name)
value = str(value)
self.accumulated_headers = ( self.accumulated_headers = (
"%s%s: %s\n" % (self.accumulated_headers, name, value)) "%s%s: %s\n" % (self.accumulated_headers, name, value))
...@@ -429,7 +433,7 @@ class HTTPResponse(BaseResponse): ...@@ -429,7 +433,7 @@ class HTTPResponse(BaseResponse):
base = '' base = ''
elif not base.endswith('/'): elif not base.endswith('/'):
base = base+'/' base = base+'/'
self.base = base self.base = str(base)
def insertBase(self, def insertBase(self,
base_re_search=re.compile('(<base.*?>)',re.I).search base_re_search=re.compile('(<base.*?>)',re.I).search
...@@ -459,6 +463,9 @@ class HTTPResponse(BaseResponse): ...@@ -459,6 +463,9 @@ class HTTPResponse(BaseResponse):
cookie has previously been set in the response object, the new cookie has previously been set in the response object, the new
value is appended to the old one separated by a colon. ''' value is appended to the old one separated by a colon. '''
name = str(name)
value = str(value)
cookies = self.cookies cookies = self.cookies
if cookies.has_key(name): if cookies.has_key(name):
cookie = cookies[name] cookie = cookies[name]
...@@ -481,6 +488,8 @@ class HTTPResponse(BaseResponse): ...@@ -481,6 +488,8 @@ class HTTPResponse(BaseResponse):
when creating the cookie. The path can be specified as a keyword when creating the cookie. The path can be specified as a keyword
argument. argument.
''' '''
name = str(name)
dict = {'max_age':0, 'expires':'Wed, 31-Dec-97 23:59:59 GMT'} dict = {'max_age':0, 'expires':'Wed, 31-Dec-97 23:59:59 GMT'}
for k, v in kw.items(): for k, v in kw.items():
dict[k] = v dict[k] = v
...@@ -495,6 +504,9 @@ class HTTPResponse(BaseResponse): ...@@ -495,6 +504,9 @@ class HTTPResponse(BaseResponse):
"value". This overwrites any previously set value for the "value". This overwrites any previously set value for the
cookie in the Response object. cookie in the Response object.
''' '''
name = str(name)
value = str(value)
cookies = self.cookies cookies = self.cookies
if cookies.has_key(name): if cookies.has_key(name):
cookie = cookies[name] cookie = cookies[name]
...@@ -511,6 +523,9 @@ class HTTPResponse(BaseResponse): ...@@ -511,6 +523,9 @@ class HTTPResponse(BaseResponse):
Sets an HTTP return header "name" with value "value", Sets an HTTP return header "name" with value "value",
appending it following a comma if there was a previous value appending it following a comma if there was a previous value
set for the header. ''' set for the header. '''
name = str(name)
value = str(value)
headers = self.headers headers = self.headers
if headers.has_key(name): if headers.has_key(name):
h = headers[name] h = headers[name]
...@@ -548,6 +563,8 @@ class HTTPResponse(BaseResponse): ...@@ -548,6 +563,8 @@ class HTTPResponse(BaseResponse):
self.setStatus(status) self.setStatus(status)
self.setHeader('Location', location) self.setHeader('Location', location)
location = str(location)
if lock: if lock:
# Don't let anything change the status code. # Don't let anything change the status code.
# The "lock" argument needs to be set when redirecting # The "lock" argument needs to be set when redirecting
......
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