File: proxy_server.rb

package info (click to toggle)
ruby-http 0.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 404 kB
  • ctags: 213
  • sloc: ruby: 2,397; makefile: 7
file content (33 lines) | stat: -rw-r--r-- 684 bytes parent folder | download
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