twitter-status-bot/.gems/gems/http-0.6.2/spec/support/proxy_server.rb

32 lines
675 B
Ruby
Raw Normal View History

2014-09-03 08:49:59 +00:00
require 'webrick/httpproxy'
handler = proc { |_, res| res['X-PROXIED'] = true }
ProxyServer = WEBrick::HTTPProxyServer.new(
:Port => 8080,
:AccessLog => [],
:RequestCallback => handler
)
AuthenticatedProxyServer = WEBrick::HTTPProxyServer.new(
:Port => 8081,
:ProxyAuthProc => proc do | req, res |
WEBrick::HTTPAuth.proxy_basic_auth(req, res, 'proxy') do | user, pass |
user == 'username' && pass == 'password'
end
end,
:RequestCallback => handler
)
Thread.new { ProxyServer.start }
trap('INT') do
ProxyServer.shutdown
exit
end
Thread.new { AuthenticatedProxyServer.start }
trap('INT') do
AuthenticatedProxyServer.shutdown
exit
end