Created
September 30, 2010 14:08
-
-
Save cayblood/604622 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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