Module: HTTPX::Plugins::DigestAuth::InstanceMethods

Defined in:
lib/httpx/plugins/digest_authentication.rb

Instance Method Summary collapse

Instance Method Details

#digest_authentication(user, password) ⇒ Object Also known as: digest_auth



32
33
34
# File 'lib/httpx/plugins/digest_authentication.rb', line 32

def digest_authentication(user, password)
  with(digest: Authentication::Digest.new(user, password))
end

#send_requests(*requests) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/httpx/plugins/digest_authentication.rb', line 38

def send_requests(*requests)
  requests.flat_map do |request|
    digest = request.options.digest

    next super(request) unless digest

    probe_response = wrap { super(request).first }

    return probe_response unless probe_response.is_a?(Response)

    if probe_response.status == 401 && digest.can_authenticate?(probe_response.headers["www-authenticate"])
      request.transition(:idle)
      request.headers["authorization"] = digest.authenticate(request, probe_response.headers["www-authenticate"])
      super(request)
    else
      probe_response
    end
  end
end