Send Authorization Header without receiving 401
Authentication scheme.
Creates new BasicAuth filter.
# File lib/httpclient/auth.rb, line 224 def initialize super @cred = nil @auth = {} @challenge = {} @scheme = "Basic" @force_auth = false end
Challenge handler: remember URL for response.
# File lib/httpclient/auth.rb, line 277 def challenge(uri, param_str = nil) synchronize { @challenge[urify(uri)] = true true } end
Response handler: returns credential. It sends cred only when a given uri is;
child page of challengeable(got *Authenticate before) uri and,
child page of defined credential
# File lib/httpclient/auth.rb, line 263 def get(req) target_uri = req.header.request_uri synchronize { return nil if !@force_auth and !@challenge.any? { |uri, ok| Util.uri_part_of(target_uri, uri) and ok } return @cred if @cred Util.hash_find_value(@auth) { |uri, cred| Util.uri_part_of(target_uri, uri) } } end
Resets challenge state. Do not send '*Authorization' header until the server sends '*Authentication' again.
# File lib/httpclient/auth.rb, line 235 def reset_challenge synchronize { @challenge.clear } end
Set authentication credential. uri == nil for generic purpose (allow to use user/password for any URL).
# File lib/httpclient/auth.rb, line 243 def set(uri, user, passwd) synchronize do if uri.nil? @cred = ["#{user}:#{passwd}"].pack('m').tr("\n", '') else uri = Util.uri_dirname(uri) @auth[uri] = ["#{user}:#{passwd}"].pack('m').tr("\n", '') end end end
have we marked this as set - ie that it's valid to use in this context?
# File lib/httpclient/auth.rb, line 255 def set? @cred || @auth.any? end