Skip to content

Commit 4768cd4

Browse files
authored
FIX: Follow additional redirect status codes (#476)
Don’t throw errors if we encounter 303, 307 or 308 HTTP status codes in responses
1 parent 71698bd commit 4768cd4

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

lib/onebox/helpers.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ def self.fetch_response(location, redirect_limit: 5, domain: nil, headers: nil,
9090

9191
code = response.code.to_i
9292
unless code === 200
93-
response.error! unless [301, 302].include?(code)
93+
response.error! unless [301, 302, 303, 307, 308].include?(code)
94+
9495
return fetch_response(
9596
response['location'],
9697
redirect_limit: redirect_limit - 1,

lib/onebox/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module Onebox
4-
VERSION = "2.2.14"
4+
VERSION = "2.2.15"
55
end

spec/lib/onebox/helpers_spec.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,10 @@
5656
describe "redirects" do
5757
describe "redirect limit" do
5858
before do
59+
codes = [301, 302, 303, 307, 308]
5960
(1..6).each do |i|
60-
FakeWeb.register_uri(:get, "https://httpbin.org/redirect/#{i}", location: "https://httpbin.org/redirect/#{i - 1}", body: "", status: [302, "Found"])
61+
code = codes.pop || 302
62+
FakeWeb.register_uri(:get, "https://httpbin.org/redirect/#{i}", location: "https://httpbin.org/redirect/#{i - 1}", body: "", status: [code, "Found"])
6163
end
6264
fake("https://httpbin.org/redirect/0", "<!DOCTYPE html><p>success</p>")
6365
end

0 commit comments

Comments
 (0)