mirror of
https://github.com/sdsykes/fastimage.git
synced 2025-09-20 00:01:59 -04:00
Merge pull request #116 from PikachuEXE/fix-incorrect-redirect-response-handling
Fix handling of redirect response without Location header
This commit is contained in:
commit
099c5e4233
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user