Class: HTTPClient::DigestAuth

Inherits:
Object
  • Object
show all
Defined in:
lib/httpclient.rb

Overview

HTTPClient::DigestAuth

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDigestAuth

Returns a new instance of DigestAuth.



452
453
454
455
456
457
# File 'lib/httpclient.rb', line 452

def initialize
  @auth = {}
  @challenge = {}
  @nonce_count = 0
  @scheme = "Digest"
end

Instance Attribute Details

#schemeObject (readonly)

:nodoc:



450
451
452
# File 'lib/httpclient.rb', line 450

def scheme
  @scheme
end

Instance Method Details

#challenge(uri, param_str) ⇒ Object



485
486
487
488
# File 'lib/httpclient.rb', line 485

def challenge(uri, param_str)
  @challenge[uri] = Util.parse_challenge_param(param_str)
  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


471
472
473
474
475
476
477
478
479
480
481
482
483
# File 'lib/httpclient.rb', line 471

def get(req)
  target_uri = req.header.request_uri
  param = Util.hash_find_value(@challenge) { |uri, param|
    Util.uri_part_of(target_uri, uri)
  }
  return nil unless param
  user, passwd = Util.hash_find_value(@auth) { |uri, auth_data|
    Util.uri_part_of(target_uri, uri)
  }
  return nil unless user
  uri = req.header.request_uri
  calc_cred(req.header.request_method, uri, user, passwd, param)
end

#reset_challengeObject



459
460
461
# File 'lib/httpclient.rb', line 459

def reset_challenge
  @challenge.clear
end

#set(uri, user, passwd) ⇒ Object



463
464
465
466
# File 'lib/httpclient.rb', line 463

def set(uri, user, passwd)
  uri = Util.uri_dirname(uri)
  @auth[uri] = [user, passwd]
end