Do not normalize URL before fetching it (#26219)
This commit is contained in:
parent
51768de16e
commit
fd284311e7
3 changed files with 143 additions and 4 deletions
|
@ -68,13 +68,26 @@ class Request
|
|||
# about 15s in total
|
||||
TIMEOUT = { connect_timeout: 5, read_timeout: 10, write_timeout: 10, read_deadline: 30 }.freeze
|
||||
|
||||
# Workaround for overly-eager decoding of percent-encoded characters in Addressable::URI#normalized_path
|
||||
# https://github.com/sporkmonger/addressable/issues/366
|
||||
URI_NORMALIZER = lambda do |uri|
|
||||
uri = HTTP::URI.parse(uri)
|
||||
|
||||
HTTP::URI.new(
|
||||
scheme: uri.normalized_scheme,
|
||||
authority: uri.normalized_authority,
|
||||
path: Addressable::URI.normalize_path(uri.path),
|
||||
query: uri.query
|
||||
)
|
||||
end
|
||||
|
||||
include RoutingHelper
|
||||
|
||||
def initialize(verb, url, **options)
|
||||
raise ArgumentError if url.blank?
|
||||
|
||||
@verb = verb
|
||||
@url = Addressable::URI.parse(url).normalize
|
||||
@url = URI_NORMALIZER.call(url)
|
||||
@http_client = options.delete(:http_client)
|
||||
@allow_local = options.delete(:allow_local)
|
||||
@options = options.merge(socket_class: use_proxy? || @allow_local ? ProxySocket : Socket)
|
||||
|
@ -139,7 +152,7 @@ class Request
|
|||
end
|
||||
|
||||
def http_client
|
||||
HTTP.use(:auto_inflate).follow(max_hops: 3)
|
||||
HTTP.use(:auto_inflate).use(normalize_uri: { normalizer: URI_NORMALIZER }).follow(max_hops: 3)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue