philippe langlois
2005-Dec-22 01:22 UTC
How to access request''s raw_header: HTTP hdr sent by browser
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 -- Posted via http://www.ruby-forum.com/.
Tom Fakes
2005-Dec-22 01:27 UTC
RE: How to access request''s raw_header: HTTP hdr sent by browser
Check out the request.env collection, this should have all you need, e.g. Accept-Encoding header: request.env[''HTTP_ACCEPT_ENCODING''] -----Original Message----- From: philippe langlois [mailto:philippelanglois-GANU6spQydw@public.gmane.org] Sent: Wednesday, December 21, 2005 5:23 PM To: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: [Rails] How to access request''s raw_header: HTTP hdr sent by browser 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 -- Posted via http://www.ruby-forum.com/. _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
philippe langlois
2005-Dec-22 01:32 UTC
Re: RE: How to access request''s raw_header: HTTP hdr sent by
Tom Fakes wrote:> Check out the request.env collection, this should have all you need, > e.g. > > Accept-Encoding header: request.env[''HTTP_ACCEPT_ENCODING'']That''s the problem, this is NOT RAW. And I need to have the complete collection of things (and yes, sometime ugly things) sent in the raw headers. Thanks -- Posted via http://www.ruby-forum.com/.
Philippe Langlois
2005-Dec-22 01:34 UTC
Re: How to access request''s raw_header: HTTP hdr sent by bro
Philippe Langlois 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 -- Posted via http://www.ruby-forum.com/.
Thomas Fuchs
2005-Dec-22 09:32 UTC
Re: Re: How to access request''s raw_header: HTTP hdr sent by bro
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 For a typical FastCGI call, see the first example here: 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 Langlois:> Philippe Langlois 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 > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Philippe Langlois
2005-Dec-22 10:27 UTC
Re: Re: How to access request''s raw_header: HTTP hdr sent by
Thomas Fuchs 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. -- Posted via http://www.ruby-forum.com/.