# Capturing referer in webrick proxy

**URL:** <https://www.ruby-forum.com/t/capturing-referer-in-webrick-proxy/132346>\
**Category:** Ruby\
**Created:** [March 19, 2008, 10:50am UTC](https://www.ruby-forum.com/t/capturing-referer-in-webrick-proxy/132346 "2008-03-19T10:50:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![and80](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e9a140/32.png) [@and80](https://www.ruby-forum.com/u/and80)\
**Post date:** [March 19, 2008, 10:50am UTC](https://www.ruby-forum.com/t/capturing-referer-in-webrick-proxy/132346/1 "2008-03-19T10:50:35Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![and80](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e9a140/32.png) [@and80](https://www.ruby-forum.com/u/and80)\
**Post date:** [March 21, 2008, 4:15pm UTC](https://www.ruby-forum.com/t/capturing-referer-in-webrick-proxy/132346/2 "2008-03-21T16:15:49Z")

</div>

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
