capturing referer in webrick proxy

A

And80

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.org/#example

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

GOTO Kentaro

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top