1require "webrick"
2require "webrick/httpproxy"
3
4# The :ProxyContentHandler proc will be invoked before sending a response to
5# the User-Agent.  You can inspect the pair of request and response messages
6# (or edit the response message if necessary).
7
8pch = Proc.new{|req, res|
9  p [ req.request_line, res.status_line ]
10}
11
12def upstream_proxy
13  if prx = ENV["http_proxy"]
14    return URI.parse(prx)
15  end
16  return nil
17end
18
19httpd = WEBrick::HTTPProxyServer.new(
20  :Port     => 10080,
21  :ProxyContentHandler => pch,
22  :ProxyURI => upstream_proxy
23)
24Signal.trap(:INT){ httpd.shutdown }
25httpd.start
26