Files

HTTPClient::ProxyAuth

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.

Attributes

basic_auth[R]
negotiate_auth[R]
sspi_negotiate_auth[R]

Public Class Methods

new() click to toggle source

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

Public Instance Methods

filter_request(req) click to toggle source

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_response(req, res) click to toggle source

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
reset_challenge() click to toggle source

Resets challenge state. See sub filters for more details.

     # File lib/httpclient/auth.rb, line 160
160:     def reset_challenge
161:       @authenticator.each do |auth|
162:         auth.reset_challenge
163:       end
164:     end
set_auth(user, passwd) click to toggle source

Set authentication credential. See sub filters for more details.

     # File lib/httpclient/auth.rb, line 167
167:     def set_auth(user, passwd)
168:       @authenticator.each do |auth|
169:         auth.set(nil, user, passwd)
170:       end
171:       reset_challenge
172:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.