public
Created

  • Download Gist
HTTP proxy example
Ruby
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 34 35 36 37 38 39
#!/usr/bin/env ruby
require 'rubygems'
require 'net/ntlm'
require 'webrick/httpproxy'
 
class ProxyServer
def pre_handler(req, res)
# check if this request applies to a previously authenticated
# realm and send Authorization header if so
end
def post_handler(req, res)
# check for the presence of the www-authenticate header and retry
# the request with the Authorization header set
end
def initialize
@server = WEBrick::HTTPProxyServer.new(
:Port => '9090',
:LogFile => $stdout,
:BindAddress => "0.0.0.0",
 
:RequestCallback => method(:pre_handler),
:ProxyContentHandler => method(:post_handler)
)
end
def start
@server.start
end
 
def stop
@server.shutdown
end
end
 
ps = ProxyServer.new
%w[INT HUP].each { |signal| trap(signal) { ps.stop } }
ps.start

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.