[Twisted-web] Headers dictionary

Jean-Paul Calderone exarkun at divmod.com
Wed Feb 21 08:38:14 CST 2007


On Wed, 21 Feb 2007 14:13:20 +0100, Jarek Zgoda <jarek.zgoda at gmail.com> wrote:
>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



More information about the Twisted-web mailing list