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