Merge pull request #116 from PikachuEXE/fix-incorrect-redirect-response-handling

Fix handling of redirect response without Location header
This commit is contained in:
Stephen Sykes 2020-06-22 06:59:01 +03:00 committed by GitHub
commit 099c5e4233
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View File

@ -296,7 +296,10 @@ class FastImage
if res.is_a?(Net::HTTPRedirection) && @redirect_count < 4
@redirect_count += 1
begin
@parsed_uri = URI.join(@parsed_uri, escaped_location(res['Location']))
location = res['Location']
raise ImageFetchFailure if location.nil? || location.empty?
@parsed_uri = URI.join(@parsed_uri, escaped_location(location))
rescue URI::InvalidURIError
else
fetch_using_http_from_parsed_uri

View File

@ -300,6 +300,13 @@ class FastImageTest < Test::Unit::TestCase
assert_equal GoodFixtures[GoodFixtures.keys.first][1], FastImage.size(TestUrl, :raise_on_failure=>true)
end
def test_should_handle_permanent_redirect_with_missing_location
register_redirect(TestUrl, nil)
assert_raises(FastImage::ImageFetchFailure) do
FastImage.size(TestUrl, :raise_on_failure=>true)
end
end
def register_redirect(from, to)
resp = Net::HTTPMovedPermanently.new(1.0, 302, "Moved")
resp['Location'] = to