1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
require 'webrick/httpproxy'
handler = proc do | req, res |
res['X-PROXIED'] = true
end
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
|