Hi,
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
end
end
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/
html;q=0.9,text/plain;q=0.8,image/png,/;q=0.5
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
end
end
end
… I get the CGI headers (request.body is empty, is that correct?) …
SERVER_NAMElocalhostPATH_INFOHTTP_ACCEPT_ENCODINGgzip,
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/
523.10SCRIPT_NAME/cSERVER_PROTOCOLHTTP/1.1HTTP_HOSTlocalhost:
3000HTTP_ACCEPT_LANGUAGEen-usHTTP_CACHE_CONTROLmax-
age=0REMOTE_ADDR127.0.0.1SERVER_SOFTWAREMongrel 1.0.1REQUEST_PATH/
cHTTP_COOKIE_dk_session_id=5d1bb099d2a1ba28f06a0bd60e091e3dHTTP_VERSIONHTTP/1.1REQUEST_URI/cSERVER_PORT3000GATEWAY_INTERFACECGI/1.2HTTP_ACCEPTtext/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,/;q=0.5HTTP_CONNECTIONkeep-aliveREQUEST_METHODGET
Is is possible to get to the raw request from within a Mongrel handler?
Many thanks,
-Paul