request.env and accessing raw header requests

I'd like to get the raw http request from a client so I can capture it
- warts and all.

I know it's possible to access the attributes from within a request
using request.env (e.g. request.env["HTTP_ACCEPT"] to get the accept
header). However, I want the actual raw header sent to the server so I
can accurately spoof the client. Building a request from the various
request.env attributes may miss things (like whether the client
incorrently sends "user_agent" or "user-agent") as I assume it does
some housekeeping (plus there could be linefeed issues etc that i'd
like to capture). In essence I want the raw!

I believe it is possible to access what is sent to WebBrick through
the doGet function, but is it possible to abstract it so it'll work on
any server environment and can I get direct access to the header
directly from my application code?

Any ideas?

Thanks,

-Paul

I have an app that captures this and you are right, clients send some
weird headers.

I have a logs and log_details where I store everything single header
for every single request.

I gather the data with a simple helper method that doubles as a hit
counter (yes, the client wanted a hit counter, how lame)

...

controller.request.env.each do |header|
       log_detail = LogDetail.new
       log_detail.log_id = log.id
       log_detail.detail_key = header[0]
       log_detail.detail_value = header[1]
       log_detail.save
end
...

And here's some of the headers I get...

This is really useful. Many thanks James - I'll let you know how I get
on...

-Paul

Hi James,

As I said, your help was really appreciated, but I think I still have
an issue.

After some further investigation it looks like request.env accesses
the CGI environment variables (a la http://hoohoo.ncsa.uiuc.edu/cgi/env.html).
I need access to the originating HTTP request sent to the server... I
wonder if anyone out there knows a way to get access to this? I know
that in php it is possible using apache_request_headers();

-Paul

Try request.env['RAW_POST_DATA'].

bijah

@request.raw_post is a wrapper for request.env['RAW_POST_DATA'].

Bijah