[Mongrel] Writing a mod_put HttpHandler

Ezra Zygmuntowicz ezmobius at gmail.com
Sun Nov 26 17:14:46 EST 2006

On Nov 26, 2006, at 1:17 PM, cremes.devlist at mac.com wrote:

> I'm looking at writing a Mongrel handler that mimics the behavior of
> the Apache mod_put [1]. It allows for the streaming upload of very
> large (GB) files; it also supports resumable upload.
> Before I get too involved, I'd like to ask if my reading of the
> mongrel source code is correct, i.e. what I want to do isn't
> currently possible.
> Looking at the class HttpRequest I see that request bodies larger
> than Mongrel::MAX_BODY get streamed to a tempfile before they are
> handed off to any handlers registered in the chain. Things were
> looking up for me when I saw the HttpHandler#request_progress call,
> but it doesn't hand the body off to the handler (only the params). In
> other words, mongrel would need to stream the entire upload to a
> tempfile before it hands off to my "PUT handler," right?
> If that's the case, any suggestions on how I could hack the code to
> hook into the HttpRequest class and redirect the write from
> "tempfile" to the real permanent file? This code path would only need
> to be activated for HTTP PUT where Content-Length is greater than
> Mongrel::MAX_BODY. Of course, I'd like that hack to allow all other
> requests to work normally.
> Thanks for any input and pointers.
> If you think I'm nuts for looking at Mongrel to do this operation,
> suggest another method that doesn't involve Apache and mod_put.

	You are correct. The way mongrel upload progress works is mongrel  
itself streams to a tmpfile before it passes the request to any  
handlers. Then by the tiem your handler gets the request it has to  
parse the mime boundaries again which is inefficient. Zed is working  
on a fast C mime carver and I am going to implement a way to grab the  
tmpfile mongrel makes without reparsing it but we haven't made  
progress yet.

	So let me know if you end up workign on this or if you want to work  
with me to come up with a way to get the first tmpfile without  

-- Ezra Zygmuntowicz 
-- Lead Rails Evangelist
-- ez at engineyard.com
-- Engine Yard, Serious Rails Hosting
-- (866) 518-YARD (9273)

More information about the Mongrel-users mailing list