* io.c (rb_open_file): encoding in mode string was ignored if perm is
[ruby-svn.git] / sample / webrick / httpproxy.rb
blobbca0cc4626f357be31aaf06ea6feeb26967ac6ed
1 require "webrick"
2 require "webrick/httpproxy"
4 # :ProxyContentHandler will be invoked before sending
5 # response to User-Agenge. You can inspect the pair of
6 # request and response messages (or can edit the response
7 # message if necessary).
9 pch = Proc.new{|req, res|
10   p [ req.request_line, res.status_line ]
13 def upstream_proxy
14   if prx = ENV["http_proxy"]
15     return URI.parse(prx)
16   end
17   return nil
18 end
20 httpd = WEBrick::HTTPProxyServer.new(
21   :Port     => 10080,
22   :ProxyContentHandler => pch,
23   :ProxyURI => upstream_proxy
25 Signal.trap(:INT){ httpd.shutdown }
26 httpd.start