Fix handling of redirect response without Location header

This commit is contained in:
PikachuEXE 2020-06-18 11:56:03 +08:00
parent 8386e11db4
commit 45521bfd3e
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