[Medusa-dev] [PATCH] medusa.http_server to handle multiple response headers with same name

Jason Sibre jsibre at chironsys.com
Mon Feb 16 16:32:36 EST 2004


Attached is a patch for medusa, (and a patch for quixote to make it work
ideally with the patched medusa) which enables medusa to have more than one
header in a reply with the same name.  The existing implementation uses a
dict, which is easy, but it prevents multiple headers of the same name from
being set.  This is an issue (for instance) when trying to set two cookies
in the course of a single request:  Only one will make it to the browser
(this is what bit me).

This repair is made more complicated than it might otherwise be, because the
api in the medusa request object reveals the dict orientation of the header
storage, and in fact, some operations are impossible without working
directly with the dict object(removing a header, for example).

What I've done is add a list object for handling the headers, and then added
a rich(er) api for working with them.  I've also left the original
implementation intact, so that someone upgrading from an old medusa to this
patched version will not notice a difference (although, they still won't be
able to have multiple headers of the same name).  My theory being that if
they upgrade, unaware of the changes, then even if they're doing fancy
things directly with the old dict object, things will keep on working, but
if they want to take advantage of the new feature, it only requires a slight
modification of how headers are added to a request object.

The new api will look at the existing dict object, and merge it's header
info with the list object's header info when called to generate the header
portion of the request.  This means that even if accesses to the headers go
through both the old and new methods, things should work as intended.  I say
'should', because may be possible to break things if you really try.

Internally, the medusa http_server module uses the new api.  Since that part
merges the dict with the list, things will work nicely whichever way a
developer goes with writing headers.

Well...  The patch is littered with comments, so I'll shut up and let the
code speak for itself.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: http_server.py.multiHeaderPatch
Type: application/octet-stream
Size: 6840 bytes
Desc: not available
Url : http://mail.python.org/pipermail/medusa-dev/attachments/20040216/6852949a/http_server.py.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: medusa_http.py.multiHeaderPatch
Type: application/octet-stream
Size: 671 bytes
Desc: not available
Url : http://mail.python.org/pipermail/medusa-dev/attachments/20040216/6852949a/medusa_http.py.obj

More information about the Medusa-dev mailing list