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.



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

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.



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

def basic_auth
  @basic_auth
end

#negotiate_authObject (readonly)

Returns the value of attribute negotiate_auth.



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

def negotiate_auth
  @negotiate_auth
end

Instance Method Details

#filter_request(req) ⇒ Object



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

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



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

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



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

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

#set_auth(user, passwd) ⇒ Object



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

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