handle 305 redirects via proxy if the plugin is enabled

This commit is contained in:
HoneyryderChuck 2022-05-24 19:04:26 +01:00
parent e740a38bad
commit d39e7ba8d4

View File

@ -86,10 +86,22 @@ module HTTPX
redirect_uri = __get_location_from_response(response)
max_redirects = request.max_redirects
# redirects are **ALWAYS** GET
retry_options = options.merge(headers: request.headers,
body: request.body,
max_redirects: max_redirects - 1)
if response.status == 305 && options.respond_to?(:proxy)
# The requested resource MUST be accessed through the proxy given by
# the Location field. The Location field gives the URI of the proxy.
retry_options = options.merge(headers: request.headers,
proxy: { uri: redirect_uri },
body: request.body,
max_redirects: max_redirects - 1)
redirect_uri = request.url
else
# redirects are **ALWAYS** GET
retry_options = options.merge(headers: request.headers,
body: request.body,
max_redirects: max_redirects - 1)
end
build_request(:get, redirect_uri, retry_options)
end