getHeader as it is in Zope3's HTTPRequest.

parent 8f11b96f
......@@ -1082,7 +1082,7 @@ class HTTPRequest(BaseRequest):
clone['PARENTS']=[self['PARENTS'][-1]]
return clone
def get_header(self, name, default=None):
def getHeader(self, name, default=None, literal=False):
"""Return the named HTTP header, or an optional default
argument or None if the header is not found. Note that
both original and CGI-ified header names are recognized,
......@@ -1090,7 +1090,8 @@ class HTTPRequest(BaseRequest):
should all return the Content-Type header, if available.
"""
environ=self.environ
name=('_'.join(name.split("-"))).upper()
if not literal:
name = name.replace('-', '_').upper()
val=environ.get(name, None)
if val is not None:
return val
......@@ -1098,6 +1099,8 @@ class HTTPRequest(BaseRequest):
name='HTTP_%s' % name
return environ.get(name, default)
get_header = getHeader # BBB
def get(self, key, default=None, returnTaints=0,
URLmatch=re.compile('URL(PATH)?([0-9]+)$').match,
BASEmatch=re.compile('BASE(PATH)?([0-9]+)$').match,
......
......@@ -801,6 +801,30 @@ class RequestTests( unittest.TestCase ):
request = HTTPRequest(s, env, None)
self.assertEqual(request.getClientAddr(), '')
def testGetHeader(self):
s = StringIO('')
env = TEST_ENVIRON.copy()
request = HTTPRequest(s, env, None)
self.assertEqual(request.getHeader('Content-Type'),
'multipart/form-data; boundary=12345')
# getHeader is agnostic of case
self.assertEqual(request.getHeader('content-type'),
'multipart/form-data; boundary=12345')
# and of dashes vs. underscores
self.assertEqual(request.getHeader('content_type'),
'multipart/form-data; boundary=12345')
# the 'literal' argument can turn this normalization off:
self.assertEqual(request.getHeader('Content-Type', literal=True), None)
# the 'default' argument can be used to get something other than
# None when the lookup fails:
self.assertEqual(request.getHeader('Not-existant', default='Whatever'),
'Whatever')
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(AuthCredentialsTests, 'test'))
......
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