[Zope-Checkins]
SVN: Zope/branches/philikon-aq/lib/python/ZPublisher/
getHeader as it is in Zope3's HTTPRequest.
Philipp von Weitershausen
philikon at philikon.de
Sun Jul 29 11:36:06 EDT 2007
Log message for revision 78465:
getHeader as it is in Zope3's HTTPRequest.
Changed:
U Zope/branches/philikon-aq/lib/python/ZPublisher/HTTPRequest.py
U Zope/branches/philikon-aq/lib/python/ZPublisher/tests/testHTTPRequest.py
-=-
Modified: Zope/branches/philikon-aq/lib/python/ZPublisher/HTTPRequest.py
===================================================================
--- Zope/branches/philikon-aq/lib/python/ZPublisher/HTTPRequest.py 2007-07-29 15:28:56 UTC (rev 78464)
+++ Zope/branches/philikon-aq/lib/python/ZPublisher/HTTPRequest.py 2007-07-29 15:36:05 UTC (rev 78465)
@@ -1082,7 +1082,7 @@
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 @@
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 @@
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,
Modified: Zope/branches/philikon-aq/lib/python/ZPublisher/tests/testHTTPRequest.py
===================================================================
--- Zope/branches/philikon-aq/lib/python/ZPublisher/tests/testHTTPRequest.py 2007-07-29 15:28:56 UTC (rev 78464)
+++ Zope/branches/philikon-aq/lib/python/ZPublisher/tests/testHTTPRequest.py 2007-07-29 15:36:05 UTC (rev 78465)
@@ -801,6 +801,30 @@
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'))
More information about the Zope-Checkins
mailing list