[ZCM] [ZC] 2320/ 2 Comment "HTTPResponse setHeader lowercases keys but getHeader does not"

"Collector: Zope Bugs, Features, and Patches ..." <[email protected]> Sun, 06 May 2007 15:58:29 -0400
Newsgroups gmane.comp.web.zope.devel.collector-monitor
Message-ID <[email protected]>
Issue #2320 Update (Comment) "HTTPResponse setHeader lowercases keys but getHeader does not"
 Status Pending, Zope/bug medium
To followup, visit:
  http://www.zope.org/Collectors/Zope/2320

==============================================================
= Comment - Entry #2 by hannosch on May 6, 2007 3:58 pm

The patch has been applied to both the 2.10 branch as well as trunk. Issue can be closed.
________________________________________
= Request - Entry #1 by hannosch on May 3, 2007 4:39 pm


Uploaded:  "httpresponse.patch"
 - http://www.zope.org/Collectors/Zope/2320/httpresponse.patch/view
The setHeader method of the HTTPResponse automatically lowercases the keys, but the getHeader method doesn't. This leads to the following unexpected behaviour:

 >>> response = HTTPResponse()

 >>> response.setHeader('Content-Type', 'foo')
 >>> response.getHeader('Content-Type')
 None
 >>> response.getHeader('content-type')
 'foo'

The attached patch solves this issue by bringing the Zope2 HTTPResponse in-line with the one from Zope3 which provides the same automatic lowercasing on the getHeader method. The example then reads:

 >>> response.setHeader('Content-Type', 'foo')
 >>> response.getHeader('Content-Type')
 'foo'
 >>> response.getHeader('content-type')
 'foo'

This has been found as most code in Zope3 (in this case zope.app.pagetemplate.viewpagetemplatefile) checks for "response.getHeader('Content-Type')" and overwrites the content type via setHeader if not found.

If nobody objects I will apply this patch to the 2.10 branch and the trunk.
==============================================================