Class: HTTPClient::ProxyAuth

Inherits:
AuthFilterBase show all
Defined in:
lib/httpclient.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeProxyAuth

Returns a new instance of ProxyAuth.



646
647
648
649
650
651
# File 'lib/httpclient.rb', line 646

def initialize
  @basic_auth = BasicAuth.new
  @negotiate_auth = NegotiateAuth.new
  # sort authenticators by priority
  @authenticator = [@negotiate_auth, @basic_auth]
end

Instance Attribute Details

#basic_authObject (readonly)

Returns the value of attribute basic_auth.



643
644
645
# File 'lib/httpclient.rb', line 643

def basic_auth
  @basic_auth
end

#negotiate_authObject (readonly)

Returns the value of attribute negotiate_auth.



644
645
646
# File 'lib/httpclient.rb', line 644

def negotiate_auth
  @negotiate_auth
end

Instance Method Details

#filter_request(req) ⇒ Object



663
664
665
666
667
668
669
670
# File 'lib/httpclient.rb', line 663

def filter_request(req)
  @authenticator.each do |auth|
    if cred = auth.get(req)
      req.header.set('Proxy-Authorization', auth.scheme + " " + cred)
      return
    end
  end
end

#filter_response(req, res) ⇒ Object



672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
# File 'lib/httpclient.rb', line 672

def filter_response(req, res)
  command = nil
  uri = req.header.request_uri
  if res.status == HTTP::Status::PROXY_AUTHENTICATE_REQUIRED
    if challenge = parse_authentication_header(res, 'proxy-authenticate')
      challenge.each do |scheme, param_str|
        @authenticator.each do |auth|
          if scheme.downcase == auth.scheme.downcase
            challengeable = auth.challenge(uri, param_str)
            command = :retry if challengeable
          end
        end
      end
      # ignore unknown authentication scheme
    end
  end
  command
end

#reset_challengeObject



653
654
655
656
657
# File 'lib/httpclient.rb', line 653

def reset_challenge
  @authenticator.each do |auth|
    auth.reset_challenge
  end
end

#set_auth(user, passwd) ⇒ Object



659
660
661
# File 'lib/httpclient.rb', line 659

def set_auth(user, passwd)
  @basic_auth.set(nil, user, passwd)
end