Class: HTTPClient::BasicAuth

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

Overview

HTTPClient::BasicAuth – BasicAuth repository.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBasicAuth

Returns a new instance of BasicAuth.



397
398
399
400
401
402
# File 'lib/httpclient.rb', line 397

def initialize
  @cred = nil
  @auth = {}
  @challengeable = {}
  @scheme = "Basic"
end

Instance Attribute Details

#schemeObject (readonly)

:nodoc:



395
396
397
# File 'lib/httpclient.rb', line 395

def scheme
  @scheme
end

Instance Method Details

#challenge(uri, param_str) ⇒ Object



432
433
434
435
# File 'lib/httpclient.rb', line 432

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


421
422
423
424
425
426
427
428
429
430
# File 'lib/httpclient.rb', line 421

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_challengeObject



404
405
406
# File 'lib/httpclient.rb', line 404

def reset_challenge
  @challengeable.clear
end

#set(uri, user, passwd) ⇒ Object

uri == nil for generic purpose



409
410
411
412
413
414
415
416
# File 'lib/httpclient.rb', line 409

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