Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/faraday/response_body_size_limit/middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ def call(env) # rubocop:disable Metrics/MethodLength
end
end

Faraday::Request.register_middleware(
Faraday::Response.register_middleware(
response_body_size_limit: Faraday::ResponseBodySizeLimit::Middleware
)
4 changes: 2 additions & 2 deletions lib/twingly/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,6 @@ def create_http_client # rubocop:disable Metrics/MethodLength
exceptions: @retryable_exceptions,
methods: [], # empty [] forces Faraday to run retry_if
retry_if: retry_if
faraday.request :response_body_size_limit,
max_size_bytes: @max_response_body_size_bytes
faraday.response :logfmt_logger, @logger.dup,
headers: true,
bodies: true,
Expand All @@ -210,6 +208,8 @@ def create_http_client # rubocop:disable Metrics/MethodLength
faraday.use FaradayMiddleware::FollowRedirects,
limit: @follow_redirects_limit
end
faraday.response :response_body_size_limit,
max_size_bytes: @max_response_body_size_bytes
faraday.adapter Faraday.default_adapter
faraday.headers[:user_agent] = user_agent
end
Expand Down
15 changes: 10 additions & 5 deletions spec/lib/twingly/http_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,11 @@ class CustomError < StandardError; end

stub_request(:any, redir_url)
.to_return(status: 302,
headers: { "Location" => "#{base_redir_url}#{n + 1}" })
headers: { "Location" => "#{base_redir_url}#{n + 1}" },
body: "redirect...")
end

stub_request(:any, "#{base_redir_url}#{times}").to_return(status: 200)
stub_request(:any, "#{base_redir_url}#{times}").to_return(status: 200, body: "finished!")
end
end

Expand All @@ -150,9 +151,13 @@ class CustomError < StandardError; end
it do
is_expected.to match(headers: {},
status: 200,
body: "",
body: "finished!",
final_url: "http://redirect.1")
end

it "only returns the body of the final request" do
expect(response.fetch(:body)).to eq("finished!")
end
end

context "when not following redirects" do
Expand All @@ -165,7 +170,7 @@ class CustomError < StandardError; end
it do
is_expected.to match(headers: { "location" => "http://redirect.1" },
status: 302,
body: "",
body: "redirect...",
final_url: url)
end
end
Expand All @@ -182,7 +187,7 @@ class CustomError < StandardError; end
it do
is_expected.to match(headers: {},
status: 200,
body: "",
body: "finished!",
final_url: "http://redirect.5")
end
end
Expand Down
Loading