Method: HTTPClient::WWWAuth#filter_response

Defined in:
lib/httpclient/auth.rb

#filter_response(req, res) ⇒ Object

Filter API implementation. Traps HTTP response and parses ‘WWW-Authenticate’ header.

This remembers the challenges for all authentication methods available to the client. On the subsequent retry of the request, filter_request will select the strongest method.



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/httpclient/auth.rb', line 127

def filter_response(req, res)
  command = nil
  if res.status == HTTP::Status::UNAUTHORIZED
    if challenge = parse_authentication_header(res, 'www-authenticate')
      uri = req.header.request_uri
      challenge.each do |scheme, param_str|
        @authenticator.each do |auth|
          next unless auth.set? # hasn't be set, don't use it
          if scheme.downcase == auth.scheme.downcase
            challengeable = auth.challenge(uri, param_str)
            command = :retry if challengeable
          end
        end
      end
      # ignore unknown authentication scheme
    end
  end
  command
end