[Twisted-web] requestHeaders issues
Phil Christensen
phil at bubblehouse.org
Thu Jun 5 14:58:21 EDT 2008
Hi all,
I've run into a problem in Twisted.Web with a recent addition to SVN
head. The problem occurs in my WSGI gateway module, which is derived
from web2's version. When I'm creating the environment dictionary by
iterating like this:
# Propagate HTTP headers
for title in request.received_headers:
header = request.received_headers[title]
...
...
the iteration through received_headers causes the following exception:
Traceback (most recent call last):
File "/Users/phil/Workspace/modu/modu/web/wsgi.py", line 91, in
createCGIEnvironment
for title in request.received_headers:
File "/Users/phil/Workspace/Twisted/twisted/web/
http_headers.py", line 41, in __getitem__
if self._headers.hasHeader(key):
File "/Users/phil/Workspace/Twisted/twisted/web/
http_headers.py", line 247, in hasHeader
return name.lower() in self._rawHeaders
exceptions.AttributeError: 'int' object has no attribute 'lower'
After some searching, I found this patch:
r23826 | exarkun | 2008-06-02 11:06:06 -0400 (Mon, 02 Jun 2008) |
15 lines
Merge web-headers-165-2
Author: dreid, exarkun
Reviewer: therve
Fixes: #165
Add two new attributes to twisted.web.http.Request,
`requestHeaders` and
`responseHeaders`, which parallel the previous attributes
`received_headers`
and `headers`. The new attributes are preferred and provide a
structured
interface to accessing and manipulating header information,
including
multiples values per header which was unsupported by the previous
API.
`received_headers` and `headers` are not deprecated and coding
using
them will continue to work, but their use is discouraged and they
will be
deprecated at some future time.
If I make those changes and use `requestHeaders` instead, like this:
# Propagate HTTP headers
for title in request.received_headers:
header = request.received_headers[title]
...
...
I instead get the following traceback:
Traceback (most recent call last):
File "/Users/phil/Workspace/modu/modu/web/wsgi.py", line 91, in
createCGIEnvironment
for title in request.requestHeaders:
exceptions.TypeError: 'Headers' object is not iterable
which seems strange to me, since from what I can tell,
request.requestHeaders should be a http_headers._DictHeaders instance.
Should I be calling request.requestHeaders.getAllRawHeaders() and
iterate through that result instead?
Any guidance in this matter would be greatly appreciated.
Thanks again,
-phil
More information about the Twisted-web
mailing list