Originating Client Request


I’m a newbie to Mongrel, so apologies if this is a dumb question.

I’m trying to write a Mongrel handler to give my the raw client
request, however all I seem to be able to get is the CGI headers using
the Mongrel API.

I want to be able to capture the originating request, not the CGI
version as it may contain issues (like case, underscore’s rather than
hypens and any linefeed issues). It’s imperative a capture this
exactly as it was sent by the client as this is an essential part of
my rails application.

I wrote a very simple WEBrick Servlet which does this:

class OriginatingHeaderServlet < WEBrick::HTTPServlet::AbstractServlet
def do_GET(request, response)
response[‘Content-Type’] = ‘text/plain’
response.status = 200
response.body = request.to_s

which produces…

GET /header HTTP/1.1
User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-us)
AppleWebKit/523.10.3 (KHTML, like Gecko) Version/3.0.4 Safari/523.10
Accept: text/xml,application/xml,application/xhtml+xml,text/
Accept-Language: en-us
Accept-Encoding: gzip, deflate
Cookie: _dk_session_id=5d1bb099d2a1ba28f06a0bd60e091e3d
Connection: keep-alive
Host: localhost:8000

…this represents the correct raw originating headers…

When I try implementing the same thing using a Mongrel handler…

class ClientHandler < Mongrel::HttpHandler
def process(request, response)
response.start(200) do |head, out|
head[“Content-Type”] = “text/plain”
out.write request.params

… I get the CGI headers (request.body is empty, is that correct?) …

deflateHTTP_USER_AGENTMozilla/5.0 (Macintosh; U; Intel Mac OS X; en-
us) AppleWebKit/523.10.3 (KHTML, like Gecko) Version/3.0.4 Safari/

Is is possible to get to the raw request from within a Mongrel handler?

Many thanks,


You could try rewinding request.body and re-reading it, although I’m
not sure mongrel puts the whole request there… It’s gotta process
the header enough in order to find your handler in the first place, so
you may be out of luck here.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs