[mod_python] HTTP mime header decoding

Philip Scott Philip.Scott at cantabcapital.com
Tue Jul 28 11:38:43 EDT 2009

Hi all,
I was intending to post this to the -dev list, but it appears to have
moved somewhere I cannot find it, so hopefully this email will find the
right eyes.
I recently upgraded our mod_python from an old version (circa 2004) to
the latest and greatest Ubuntu had to offer, and unfortunately this
caused a bit of a regression in our system. We have to interface with a
rather obscure client, which sends its data through a HTTP POST request
as a multipart message separated nicely with boundaries, but which does
not add a new line or carriage return after the final boundary. I am not
sure whether this is permitted in the standard, but it worked in the old
version - I think some changes to improve multi-line handling (adding
the use of a boundary regex) upset this.
I have a very small patch for util.py which fixes this on my end, and I
think should be benign. If someone in the know would like to check it
won't have any unintended side effects, it would be great to stick it in
the tree; perhaps there are some more obscure clients that do this as

	--- util.py.orig        2009-07-28 16:08:00.000000000 +0100
	+++ util.py     2009-07-28 16:08:19.000000000 +0100
	@@ -237,7 +237,7 @@
	             boundary = ctype[i+9:]
	             if len(boundary) >= 2 and boundary[0] ==
boundary[-1] == '"':
	                 boundary = boundary[1:-1]
	-            boundary = re.compile("--" + re.escape(boundary) +
	+            boundary = re.compile("--" + re.escape(boundary) +
	         except ValueError:
	             raise apache.SERVER_RETURN, apache.HTTP_BAD_REQUEST

I think that since we get the line we compare to boundary using
readline() anyway, it is safe to make the final \n optional. It
certainly appears to work..
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mm_cfg_has_not_been_edited_to_set_host_domains/pipermail/mod_python/attachments/20090728/f8fb0028/attachment.html

More information about the Mod_python mailing list