[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

capturing referer in webrick proxy

And80

3/19/2008 9:46:00 AM

Hi all,
I am doing a small proxy using the WEBrick::HTTPProxyServer class and
I would like to capture the
referer of each HTTP request. Specifically, I need it in order to keep
trace of the html page linking to other in-line meda
(such as gif,png,etc...).

this is my stub code for the proxy looks like:

#from http://www.webrick.or...

require 'webrick/httpproxy'
s = WEBrick::HTTPProxyServer.new(
:Port => 2200,
:ProxyContentHandler => Proc.new{|req,res|
#request handling here
}
)
trap("INT"){ s.shutdown }
s.start

1 Answer

GOTO Kentaro

3/21/2008 3:15:00 PM

0

Hi,

WEBrick provides a simple access log formatter.
You can specify another format. See webrick/accesslog.
Another way is use of :RequestCallback instead of :ProxyContentHandler.
A redundant example of both of them:

require 'webrick/httpproxy'
require 'webrick/accesslog'

s = WEBrick::HTTPProxyServer.new(
:Port => 2200,
:AccessLog => [
[ $stderr, WEBrick::AccessLog::REFERER_LOG_FORMAT ]
],
:RequestCallback => proc{|req,res|
puts "Referer: #{req.header["referer"]}"
}
)
trap("INT"){ s.shutdown }
s.start


HTH,

Gotoken

On Wed, Mar 19, 2008 at 6:49 PM, And80 <a.flow@tiscali.it> wrote:
> Hi all,
> I am doing a small proxy using the WEBrick::HTTPProxyServer class and
> I would like to capture the
> referer of each HTTP request. Specifically, I need it in order to keep
> trace of the html page linking to other in-line meda
> (such as gif,png,etc...).
>
> this is my stub code for the proxy looks like:
>
> #from http://www.webrick.or...
>
> require 'webrick/httpproxy'
> s = WEBrick::HTTPProxyServer.new(
> :Port => 2200,
> :ProxyContentHandler => Proc.new{|req,res|
> #request handling here
> }
> )
> trap("INT"){ s.shutdown }
> s.start
>
>
>