Merge branch 'check-response-class'

This commit is contained in:
HoneyryderChuck 2022-12-23 18:31:01 +00:00
commit 06274364ef
9 changed files with 25 additions and 7 deletions

View File

@ -63,7 +63,11 @@ module HTTPX::Plugins
request_info = extract_request_info(req)
sentry_span.set_description("#{request_info[:method]} #{request_info[:url]}")
sentry_span.set_data(:status, res.status)
if res.is_a?(HTTPX::ErrorResponse)
sentry_span.set_data(:error, res.message)
else
sentry_span.set_data(:status, res.status)
end
sentry_span.set_timestamp(::Sentry.utc_now.to_f)
end

View File

@ -46,6 +46,8 @@ module HTTPX
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"])

View File

@ -50,7 +50,8 @@ module HTTPX
end
def response=(response)
if response && response.status == 100 &&
if response.is_a?(Response) &&
response.status == 100 &&
!@headers.key?("expect") &&
(@state == :body || @state == :done)
@ -92,7 +93,7 @@ module HTTPX
response = @responses.delete(request)
return unless response
if response.status == 417 && request.headers.key?("expect")
if response.is_a?(Response) && response.status == 417 && request.headers.key?("expect")
response.close
request.headers.delete("expect")
request.transition(:idle)

View File

@ -44,7 +44,8 @@ module HTTPX
max_redirects = redirect_request.max_redirects
return response unless response.is_a?(Response) && REDIRECT_STATUS.include?(response.status) && response.headers.key?("location")
return response unless response.is_a?(Response)
return response unless REDIRECT_STATUS.include?(response.status) && response.headers.key?("location")
return response unless max_redirects.positive?
retry_request = build_redirect_request(redirect_request, response, options)

View File

@ -39,6 +39,8 @@ module HTTPX
request.headers["authorization"] = ntlm.negotiate
probe_response = wrap { super(request).first }
return probe_response unless probe_response.is_a?(Response)
if probe_response.status == 401 && ntlm.can_authenticate?(probe_response.headers["www-authenticate"])
request.transition(:idle)
request.headers["authorization"] = ntlm.authenticate(request, probe_response.headers["www-authenticate"])

View File

@ -23,6 +23,7 @@ module HTTPX
response = super
if response &&
response.is_a?(Response) &&
response.status == 407 &&
!request.headers.key?("proxy-authorization") &&
response.headers.key?("proxy-authenticate")
@ -113,13 +114,14 @@ module HTTPX
def __http_on_connect(request, response)
@inflight -= 1
if response.status == 200
if response.is_a?(Response) && response.status == 200
req = @pending.first
request_uri = req.uri
@io = ProxySSL.new(@io, request_uri, @options)
transition(:connected)
throw(:called)
elsif response.status == 407 &&
elsif response.is_a?(Response) &&
response.status == 407 &&
!request.headers.key?("proxy-authorization") &&
@options.proxy.can_authenticate?(response.headers["proxy-authenticate"])

View File

@ -23,6 +23,8 @@ module HTTPX
end
def retry_on_rate_limited_response(response)
return false unless response.is_a?(Response)
status = response.status
RATE_LIMIT_CODES.include?(status)

View File

@ -35,7 +35,9 @@ module HTTPX
response = super
if response
return response unless response.respond_to?(:headers) && response.headers.key?("upgrade")
return response unless response.is_a?(Response)
return response unless response.headers.key?("upgrade")
upgrade_protocol = response.headers["upgrade"].split(/ *, */).first

View File

@ -32,6 +32,8 @@ module HTTPX
"</D:lockinfo>"
response = request(:lock, path, headers: headers, xml: xml)
return response unless response.is_a?(Response)
return response unless blk && response.status == 200
lock_token = response.headers["lock-token"]