# How to access request's raw\_header: HTTP hdr sent by browser

**URL:** <https://www.ruby-forum.com/t/how-to-access-requests-raw-header-http-hdr-sent-by-browser/74312>\
**Category:** Rails\
**Created:** [December 22, 2005, 2:22am UTC](https://www.ruby-forum.com/t/how-to-access-requests-raw-header-http-hdr-sent-by-browser/74312 "2005-12-22T02:22:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![philpraxis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/77aa72/32.png) [@philpraxis](https://www.ruby-forum.com/u/philpraxis)\
**Post date:** [December 22, 2005, 2:22am UTC](https://www.ruby-forum.com/t/how-to-access-requests-raw-header-http-hdr-sent-by-browser/74312/1 "2005-12-22T02:22:36Z")

</div>

Is that something possible, i’ve been trying to get to the RAW headers  
sent during a GET request on a page, and couldn’t find where. I’m using  
webrick.

Here are the tries I did to get access to it:

class ZController \< ApplicationController  
def info  
#render :inline =\> request.inspect  
#render :inline =\> raw\_header.inspect  
#render :inline =\> request\_line.inspect  
#render :inline =\> req.inspect  
#render :inline =\> meta.inspect  
#render :inline =\> header.inspect  
#render :inline =\> headers.inspect # --\> response headers  
#render :inline =\> $:.inspect  
#render :inline =\> $\*.inspect  
#render :inline =\> $".inspect  
#render :inline =\> @request.inspect  
render :inline =\> inspect  
end  
end

In the scope of the controller, I can’t find such info. It seems it  
could be very useful but it would somewhat be corrupting the neat  
dependency on the CGI convention. I don’t care too much about this, if  
it requires some tweaking of webrick or RoR, it’s ok, but I would need  
to know what the simplest way.  
Thanks

---

<div class="post-metadata">

**Author:** ![philpraxis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/77aa72/32.png) [@philpraxis](https://www.ruby-forum.com/u/philpraxis)\
**Post date:** [December 22, 2005, 2:34am UTC](https://www.ruby-forum.com/t/how-to-access-requests-raw-header-http-hdr-sent-by-browser/74312/2 "2005-12-22T02:34:41Z")

</div>

Philippe L. wrote:

> Is that something possible, i’ve been trying to get to the RAW headers  
> sent during a GET request on a page, and couldn’t find where. I’m using  
> webrick.  
> I forgot to explain what is really RAW:  
> it’s not request.env[]

it’s something that must look like:  
GET /Z/index HTTP/1.1  
Host: localhost:3000  
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.10)  
Gecko/20050911 Firefox/1.0.6 (Debian package 1.0.6-5)  
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,en;q=0.5  
Accept-Encoding: gzip,deflate  
Accept-Charset: ISO-8859-1,utf-8;q=0.7,\*;q=0.7  
Keep-Alive: 300  
Connection: keep-alive  
Cookie: \_session\_id=049d26a05baf3d6048b153c50e29fed3  
Cache-Control: max-age=0

---

<div class="post-metadata">

**Author:** ![philpraxis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/77aa72/32.png) [@philpraxis](https://www.ruby-forum.com/u/philpraxis)\
**Post date:** [December 22, 2005, 10:34am UTC](https://www.ruby-forum.com/t/how-to-access-requests-raw-header-http-hdr-sent-by-browser/74312/3 "2005-12-22T10:34:59Z")

</div>

Rails runs in a CGI environment, where the Webserver provides  
various information with environment vars (and strips the headers  
from the request).

For example, take FastCGI processes running seperately from the  
Webserver,  
where the Webserver just calls them. Rails never gets to see raw  
headers in the  
first place. (with FastCGI the enviroment vars are part of the  
FastCGI protocol).

So, you have to stick to request.env, no raw headers here.

For more on how the CGI protocol handles HTTP headers, look here:  
[http://hoohoo.ncsa.uiuc.edu/cgi/env.html](http://hoohoo.ncsa.uiuc.edu/cgi/env.html)

For a typical FastCGI call, see the first example here:  
[http://www.fastcgi.com/devkit/doc/fcgi-spec.html#SB](http://www.fastcgi.com/devkit/doc/fcgi-spec.html#SB)  
(notice how FCGI\_PARAMS contains the stuff you’ll find in request.env,  
and FCGI\_STDIN contains nothing (it would only contain POST data, no  
headers)).

-Thomas

Am 22.12.2005 um 02:34 schrieb Philippe L.:

---

<div class="post-metadata">

**Author:** ![philpraxis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/77aa72/32.png) [@philpraxis](https://www.ruby-forum.com/u/philpraxis)\
**Post date:** [December 22, 2005, 11:27am UTC](https://www.ruby-forum.com/t/how-to-access-requests-raw-header-http-hdr-sent-by-browser/74312/4 "2005-12-22T11:27:47Z")

</div>

Thomas F. wrote:

> Rails runs in a CGI environment, where the Webserver provides  
> various information with environment vars (and strips the headers  
> from the request).  
> […]
> 
> So, you have to stick to request.env, no raw headers here.

Except if I can stick to Webrick and do something custom for Webrick.  
My question is, if I want to do that, what’s the best way?  
Can I create a do\_GET handler for Webrick which still allows me to use  
the rest of rails with no problems?  
I wouldn’t like it to be a quick hack but an extensible mechanism to  
blend in raw servlets and usual rails development.

Thus, where should I modify my Webrick/actionpack scripts to insert  
this?

Thanks,  
Philippe.
