summaryrefslogtreecommitdiff
path: root/jni/ruby/sample/webrick/httpproxy.rb
diff options
context:
space:
mode:
authorJari Vetoniemi <jari.vetoniemi@indooratlas.com>2020-03-16 18:49:26 +0900
committerJari Vetoniemi <jari.vetoniemi@indooratlas.com>2020-03-30 00:39:06 +0900
commitfcbf63e62c627deae76c1b8cb8c0876c536ed811 (patch)
tree64cb17de3f41a2b6fef2368028fbd00349946994 /jni/ruby/sample/webrick/httpproxy.rb
Fresh start
Diffstat (limited to 'jni/ruby/sample/webrick/httpproxy.rb')
-rw-r--r--jni/ruby/sample/webrick/httpproxy.rb25
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