Class: HTTPAccess2::BasicAuth

Inherits:
Object
  • Object
show all
Defined in:
lib/rss-client/http-access2.rb

Overview

HTTPAccess2::BasicAuth – BasicAuth repository.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBasicAuth

Returns a new instance of BasicAuth.



880
881
882
883
884
885
# File 'lib/rss-client/http-access2.rb', line 880

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

Instance Attribute Details

#schemeObject (readonly)

:nodoc:



878
879
880
# File 'lib/rss-client/http-access2.rb', line 878

def scheme
  @scheme
end

Instance Method Details

#challenge(uri, param_str) ⇒ Object



915
916
917
918
# File 'lib/rss-client/http-access2.rb', line 915

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


904
905
906
907
908
909
910
911
912
913
# File 'lib/rss-client/http-access2.rb', line 904

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



887
888
889
# File 'lib/rss-client/http-access2.rb', line 887

def reset_challenge
  @challengeable.clear
end

#set(uri, user, passwd) ⇒ Object

uri == nil for generic purpose



892
893
894
895
896
897
898
899
# File 'lib/rss-client/http-access2.rb', line 892

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