Class: Rack::Client::Auth::Abstract::Challenge

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/rack/client/middleware/auth/abstract/challenge.rb

Direct Known Subclasses

Basic::Challenge, Digest::Challenge

Instance Method Summary collapse

Constructor Details

#initialize(request, response) ⇒ Challenge

Returns a new instance of Challenge.



11
12
13
# File 'lib/rack/client/middleware/auth/abstract/challenge.rb', line 11

def initialize(request, response)
  @request, @response = request, response
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym) ⇒ Object



43
44
45
46
47
48
# File 'lib/rack/client/middleware/auth/abstract/challenge.rb', line 43

def method_missing(sym)
  if params.has_key? key = sym.to_s
    return params[key]
  end
  super
end

Instance Method Details

#nonceObject



35
36
37
# File 'lib/rack/client/middleware/auth/abstract/challenge.rb', line 35

def nonce
  @nonce ||= Rack::Auth::Digest::Nonce.parse(params['nonce'])
end

#paramsObject



39
40
41
# File 'lib/rack/client/middleware/auth/abstract/challenge.rb', line 39

def params
  @params ||= Rack::Auth::Digest::Params.parse(parts.last)
end

#partsObject



27
28
29
# File 'lib/rack/client/middleware/auth/abstract/challenge.rb', line 27

def parts
  @parts ||= www_authenticate if www_authenticate
end

#required?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/rack/client/middleware/auth/abstract/challenge.rb', line 15

def required?
  status == 401
end

#schemeObject



31
32
33
# File 'lib/rack/client/middleware/auth/abstract/challenge.rb', line 31

def scheme
  @scheme ||= www_authenticate.last[/^(\w+)/, 1].downcase.to_sym if www_authenticate
end

#unspecified?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/rack/client/middleware/auth/abstract/challenge.rb', line 19

def unspecified?
  scheme.nil?
end

#www_authenticateObject



23
24
25
# File 'lib/rack/client/middleware/auth/abstract/challenge.rb', line 23

def www_authenticate
  @www_authenticate ||= headers.detect {|h,_| h =~ /^WWW-AUTHENTICATE$/i }
end