Is it only me, or the field names in twisted.web.http.Request.received_headers (also returned by getAllHeaders()) are case-sensitive? The RFC states, that they should be case-insensitive (http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2), but if I set "Accept" header in client code (such as using Python's own httplib.HTTPConnection), there's no "accept" key in this dictionary, as available in resource's render_XXX method. Am I supposed to write my own HTTP compatibility layer for twisted.web, or I just overlooked something obvious? -- Jarek Zgoda http://jpa.berlios.de/
On Wed, 21 Feb 2007 14:13:20 +0100, Jarek Zgoda
Is it only me, or the field names in twisted.web.http.Request.received_headers (also returned by getAllHeaders()) are case-sensitive? The RFC states, that they should be case-insensitive (http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2), but if I set "Accept" header in client code (such as using Python's own httplib.HTTPConnection), there's no "accept" key in this dictionary, as available in resource's render_XXX method.
Am I supposed to write my own HTTP compatibility layer for twisted.web, or I just overlooked something obvious?
Can you provide an example which demonstrates the problem you're seeing? This example seems to demonstrate that all headers are lower-cased: from twisted.web.resource import Resource from twisted.web.server import Site from twisted.application.service import Application from twisted.application.internet import TCPServer class X(Resource): def getChild(self, *a): return self def render_GET(self, request): print request.getAllHeaders() return '' application = Application('HTTP Test') TCPServer(8080, Site(X())).setServiceParent(application) Hitting the server with Firefox results in a dictionary with an 'accept' key, with that spelling, regardless of the case of the input. Jean-Paul
On 2/21/07, Jean-Paul Calderone
Can you provide an example which demonstrates the problem you're seeing? This example seems to demonstrate that all headers are lower-cased:
(...)
Hitting the server with Firefox results in a dictionary with an 'accept' key, with that spelling, regardless of the case of the input.
This example is perfect, what failed is my understanding of things and my ability to express what I've seen with my code. I encountered this problem when I used the same code to generate headers for client to send and for server to check. The generated field names was in Mixed-Case (i.e. "Accept" and "Content-Type") so I got the KeyError on server side. I expected this to be irrelevant, following RFC's statement that "field names are case insensitive". Anyway, I can live with this. -- Jarek Zgoda http://jpa.berlios.de/
participants (2)
-
Jarek Zgoda
-
Jean-Paul Calderone