Skip to content

Instantly share code, notes, and snippets.

@yoshitsugu
Created August 7, 2013 09:16
Show Gist options
  • Select an option

  • Save yoshitsugu/6172494 to your computer and use it in GitHub Desktop.

Select an option

Save yoshitsugu/6172494 to your computer and use it in GitHub Desktop.
proxy with webrick
#!/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