Skip to content

Commit

Permalink
(maint) Fix valid_url? check
Browse files Browse the repository at this point in the history
Because the 'request' function does NOT return the value the block you pass it returns, this function was always returning a Net::HTTP object. With how this function was being used, it would result in valid_url? always being truthy.  Net::HTTP.start DOES return the value that the block you pass it returns, though, so this simply un-blockifies the processing of the request response.
  • Loading branch information
Nick Burgan-Illig committed Aug 25, 2023
1 parent c315b8a commit 9995d5e
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions lib/vanagon/component/source/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,19 @@ def valid_url?(target_url)
return false unless ['http', 'https'].include? uri.scheme

Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
http.request(Net::HTTP::Head.new(uri)) do |response|
case response
when Net::HTTPRedirection
# By parsing the location header, we get either an absolute
# URI or a URI with a relative `path`. Adding it to `uri`
# should correctly update the relative `path` or overwrite
# the entire URI if it's absolute.
location = URI.parse(response.header['location'])
valid_url?(uri + location)
when Net::HTTPSuccess
return true
else
false
end
response = http.request(Net::HTTP::Head.new(uri))
case response
when Net::HTTPRedirection
# By parsing the location header, we get either an absolute
# URI or a URI with a relative `path`. Adding it to `uri`
# should correctly update the relative `path` or overwrite
# the entire URI if it's absolute.
location = URI.parse(response.header['location'])
valid_url?(uri + location)
when Net::HTTPSuccess
true
else
false
end
end
end
Expand Down

0 comments on commit 9995d5e

Please sign in to comment.