diff options
Diffstat (limited to 'jni/ruby/sample/webrick/httpproxy.rb')
-rw-r--r-- | jni/ruby/sample/webrick/httpproxy.rb | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/jni/ruby/sample/webrick/httpproxy.rb b/jni/ruby/sample/webrick/httpproxy.rb new file mode 100644 index 0000000..c84457e --- /dev/null +++ b/jni/ruby/sample/webrick/httpproxy.rb @@ -0,0 +1,25 @@ +require "webrick" +require "webrick/httpproxy" + +# The :ProxyContentHandler proc will be invoked before sending a response to +# the User-Agent. You can inspect the pair of request and response messages +# (or edit the response message if necessary). + +pch = Proc.new{|req, res| + p [ req.request_line, res.status_line ] +} + +def upstream_proxy + if prx = ENV["http_proxy"] + return URI.parse(prx) + end + return nil +end + +httpd = WEBrick::HTTPProxyServer.new( + :Port => 10080, + :ProxyContentHandler => pch, + :ProxyURI => upstream_proxy +) +Signal.trap(:INT){ httpd.shutdown } +httpd.start |