Skip to content

@cayblood /HTTP proxy example
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
#!/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
Something went wrong with that request. Please try again.