Authentication filter for handling authentication negotiation between Proxy server. Parses ‘Proxy-Authentication’ header in response and generates ‘Proxy-Authorization’ header in request.
Authentication filter is implemented using request filter of HTTPClient. It traps HTTP response header and maintains authentication state, and traps HTTP request header for inserting necessary authentication header.
ProxyAuth has sub filters (BasicAuth, NegotiateAuth, and SSPINegotiateAuth) and delegates some operations to it. NegotiateAuth requires ‘ruby/ntlm’ module. SSPINegotiateAuth requires ‘win32/sspi’ module.
Creates new ProxyAuth.
# File lib/httpclient/auth.rb, line 151 151: def initialize 152: @basic_auth = BasicAuth.new 153: @negotiate_auth = NegotiateAuth.new 154: @sspi_negotiate_auth = SSPINegotiateAuth.new 155: # sort authenticators by priority 156: @authenticator = [@negotiate_auth, @sspi_negotiate_auth, @basic_auth] 157: end
Filter API implementation. Traps HTTP request and insert ‘Proxy-Authorization’ header if needed.
# File lib/httpclient/auth.rb, line 176 176: def filter_request(req) 177: @authenticator.each do |auth| 178: if cred = auth.get(req) 179: req.header.set('Proxy-Authorization', auth.scheme + " " + cred) 180: return 181: end 182: end 183: end
Filter API implementation. Traps HTTP response and parses ‘Proxy-Authenticate’ header.
# File lib/httpclient/auth.rb, line 187 187: def filter_response(req, res) 188: command = nil 189: if res.status == HTTP::Status::PROXY_AUTHENTICATE_REQUIRED 190: if challenge = parse_authentication_header(res, 'proxy-authenticate') 191: uri = req.header.request_uri 192: challenge.each do |scheme, param_str| 193: @authenticator.each do |auth| 194: if scheme.downcase == auth.scheme.downcase 195: challengeable = auth.challenge(uri, param_str) 196: command = :retry if challengeable 197: end 198: end 199: end 200: # ignore unknown authentication scheme 201: end 202: end 203: command 204: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.