ANN: http header parsing

Mark Nottingham mnot at pobox.com
Tue Aug 10 15:21:46 CEST 1999


I've been working for a little while on a module that will allow easy
parsing, manipulation and output of HTTP 1.1 headers (as defined in
RFC2616).

Although it's very alpha at this point (meaning: many bugs, interface will
probably change), I'd like to get some feedback and solicit ideas, criticism
and help from some other people. If it's done right, it could make life a
lot easier when writing CGI, clients, servers, etc.

As an example, here's some of the things you can do:

f = Headers()        # can instantiate with text or rfc822.Message instance
to parse
f.cache_control = {}
f.cache_control.max_age = 600
f.cache_control.max_age = f.cache_control.max_age - 60
f.etag = "fooboo"
f.etag.weak = 1
f.expires = time.time()
f           # output as below; can also use the putheaders() method to feed
into httplib
Cache-Control: max-age=540
ETag: W/"fooboo"
Expires: Tue, 04 Jan 1999 04:34:22 GMT


You can download from http://www.mnot.net/python/ ; you'll need both
httpheaders.py and httpheadertypes.py.

Please remember that these have NOT been extensively tested or documented,
and should not be used in a production system. I'm primarily interested in
feedback on the interface and the approach that I've taken.

Cheers,

--
Mark Nottingham
Melbourne, Australia
http://www.mnot.net/






More information about the Python-list mailing list