module HTTPX::Plugins::DigestAuthentication::InstanceMethods

  1. lib/httpx/plugins/digest_authentication.rb

Methods

Public Instance

  1. digest_authentication
  2. request

Public Instance Aliases

digest_auth -> digest_authentication

Public Instance methods

digest_authentication (user, password)
[show source]
   # File lib/httpx/plugins/digest_authentication.rb
31 def digest_authentication(user, password)
32   branch(default_options.with_digest(Digest.new(user, password)))
33 end
request (*args, **options)
[show source]
   # File lib/httpx/plugins/digest_authentication.rb
37 def request(*args, **options)
38   requests = build_requests(*args, options)
39   probe_request = requests.first
40   digest = probe_request.options.digest
41 
42   return super unless digest
43 
44   prev_response = wrap { send_requests(*probe_request, options).first }
45 
46   raise Error, "request doesn't require authentication (status: #{prev_response.status})" unless prev_response.status == 401
47 
48   probe_request.transition(:idle)
49 
50   responses = []
51 
52   while (request = requests.shift)
53     token = digest.generate_header(request, prev_response)
54     request.headers["authorization"] = "Digest #{token}"
55     response = if requests.empty?
56       send_requests(*request, options).first
57     else
58       wrap { send_requests(*request, options).first }
59     end
60     responses << response
61     prev_response = response
62   end
63 
64   responses.size == 1 ? responses.first : responses
65 end