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