[mod_python] post request and the minimalistic handler

Mike Looijmans nlv11281 at natlab.research.philips.com
Mon Feb 20 10:11:26 EST 2006


There are still some problems with the FieldStorage class and large files. If you want to upload a 
large file, you MUST use a make_file callback to the FieldStorage constructor and NEVER call 
form["file"] for that field or your apache process will load the whole file into RAM.

In other words:
- Does it work with small (e.g. 10k) files?
- Look at apache's memory usage.

--
Mike Looijmans
Philips Natlab / Topic Automation


Daniel Nogradi wrote:
> I try to figure out exactly how an actual request gets converted into
> an mp_request object, especially if its content-type is
> multpart/form-data containing an uploaded file.
> 
> As a first step (with the zeroth step being reading the source of
> publisher.py and util.py) I wanted to see what happens if the
> minimalistic handler mentioned in the docs receives a POST requests
> sent from a file upload form such as
> 
> <html><body>
> <form enctype="multipart/form-data" method="post"
> action="http://server/testhandler/x">
> <input type="file" name="upload_this">
> <input type="submit" name="go" value="Click this">
> </form>
> </body></html>
> 
> and apache is given the following:
> 
> <Directory /var/www/html/testhandler>
>     SetHandler python-program
>     PythonHandler mod_python.myhandler
>     LimitRequestBody 0
> </Directory>
> 
> and the request handler myhandler.py is:
> 
> from mod_python import apache
> 
> def handler( req ):
>      req.content_type = "text/html"
>      req.write( "hello" )
>      return apache.OK
> 
> I would assume that no matter what kind of request comes in to the
> hierarchy under /testhandler the response from the server should be
> 'hello' under all circumstances. With GET requests everything is okay,
> the response is
> 
> HTTP/1.1 200 OK
> Date: Sun, 19 Feb 2006 17:11:54 GMT
> Server: Apache/2.0.53 (Fedora)
> Connection: close
> Transfer-Encoding: chunked
> Content-Type: text/html; charset=UTF-8
> 
> 5
> hello
> 0
> 
> which gets displayed nicely by Firefox as 'hello'.
> 
> The trouble starts when POST request are coming in for example through
> the html form above. After sending the form Firefox says 'The document
> contains no data' in a warning window (actually it displays 'hello'
> once or twice, but 99% of the time it just shows the warning). However
> after checking the log files of apache it turns out that everything
> went okay with the request, a 200 code was sent and the length of the
> response is also correctly shown to be 5. So it seems that from the
> point of view of the server everything went fine, but somehow Firefox
> never gets (or it thinks it doesn't get) the 200 code and the response
> containing 'hello'.
> 
> In order to see if it was really a Firefox issue I put together the
> POST request by hand and sent it to the server with netcat and
> everything went as expected, the output was the same as above.
> 
> So it seems it is a Firefox issue, but I'm a bit surprised that such a
> simple example would not work with Firefox. Am I expecting something
> that I shouldn't?
> 
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python



More information about the Mod_python mailing list