Skip to content

Instantly share code, notes, and snippets.

@cayblood
Created September 30, 2010 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cayblood/604622 to your computer and use it in GitHub Desktop.
Save cayblood/604622 to your computer and use it in GitHub Desktop.
#!/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment