Class: HTTPClient::BasicAuth
- Inherits:
-
Object
- Object
- HTTPClient::BasicAuth
- Defined in:
- lib/httpclient.rb
Overview
HTTPClient::BasicAuth – BasicAuth repository.
Instance Attribute Summary collapse
-
#scheme ⇒ Object
readonly
:nodoc:.
Instance Method Summary collapse
- #challenge(uri, param_str) ⇒ Object
-
#get(req) ⇒ Object
send cred only when a given uri is; - child page of challengeable(got WWW-Authenticate before) uri and, - child page of defined credential.
-
#initialize ⇒ BasicAuth
constructor
A new instance of BasicAuth.
- #reset_challenge ⇒ Object
-
#set(uri, user, passwd) ⇒ Object
uri == nil for generic purpose.
Constructor Details
#initialize ⇒ BasicAuth
Returns a new instance of BasicAuth.
405 406 407 408 409 410 |
# File 'lib/httpclient.rb', line 405 def initialize @cred = nil @auth = {} @challengeable = {} @scheme = "Basic" end |
Instance Attribute Details
#scheme ⇒ Object (readonly)
:nodoc:
403 404 405 |
# File 'lib/httpclient.rb', line 403 def scheme @scheme end |
Instance Method Details
#challenge(uri, param_str) ⇒ Object
440 441 442 443 |
# File 'lib/httpclient.rb', line 440 def challenge(uri, param_str) @challengeable[uri] = true true end |
#get(req) ⇒ Object
send cred only when a given uri is;
- child page of challengeable(got WWW-Authenticate before) uri and,
- child page of defined credential
429 430 431 432 433 434 435 436 437 438 |
# File 'lib/httpclient.rb', line 429 def get(req) target_uri = req.header.request_uri return nil unless @challengeable.find { |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 |
#reset_challenge ⇒ Object
412 413 414 |
# File 'lib/httpclient.rb', line 412 def reset_challenge @challengeable.clear end |
#set(uri, user, passwd) ⇒ Object
uri == nil for generic purpose
417 418 419 420 421 422 423 424 |
# File 'lib/httpclient.rb', line 417 def set(uri, user, passwd) 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 |