Created
August 7, 2013 09:16
-
-
Save yoshitsugu/6172494 to your computer and use it in GitHub Desktop.
proxy with webrick
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| require 'webrick' | |
| require 'webrick/httpproxy' | |
| require 'uri' | |
| # プロキシサーバオブジェクトを作る | |
| s = WEBrick::HTTPProxyServer.new( | |
| # バインドアドレス(デフォルト:nil) | |
| :BindAddress => 'your_address', | |
| # ポート番号(デフォルト:80) | |
| :Port => 8080, | |
| # ログ(デフォルト:nil) | |
| :Logger => WEBrick::Log::new($stderr, WEBrick::Log::DEBUG), | |
| # proxy が通ってきたことを header で報せるか(デフォルト:true) | |
| :ProxyVia => false | |
| ) | |
| # 後処理の為に SIGINT を捕捉する。 | |
| Signal.trap('INT') do | |
| # 捕捉した場合、シャットダウンする。 | |
| s.shutdown | |
| end | |
| # サーバを起動する。 | |
| s.start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment