Skip to content

Commit

Permalink
Merge pull request #9265 from mhashizume/PUP-11983/main/http-redirects
Browse files Browse the repository at this point in the history
Remove Accept-Encoding header on redirect
  • Loading branch information
joshcooper committed Feb 27, 2024
2 parents ce909ae + d0a73bb commit 57a00cc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/puppet/http/redirector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ def redirect_to(request, response, redirects)
next if header.casecmp('Authorization').zero? && request.uri.host.casecmp(location.host) != 0
next if header.casecmp('Cookie').zero? && request.uri.host.casecmp(location.host) != 0
end
# Allow Net::HTTP to set its own Accept-Encoding header to avoid errors with HTTP compression.
# See https://github.com/puppetlabs/puppet/issues/9143
next if header.casecmp('Accept-Encoding').zero?

new_request[header] = value
end

Expand Down
11 changes: 11 additions & 0 deletions spec/unit/http/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,17 @@ def redirect_to(status: 302, url:)
response = client.get(https)
expect(response).to be_success
end

it "does not preserve accept-encoding header when redirecting" do
headers = { 'Accept-Encoding' => 'unwanted-encoding'}

stub_request(:get, start_url).with(headers: headers).to_return(redirect_to(url: other_host))
stub_request(:get, other_host).to_return(status: 200)

client.get(start_url, headers: headers)
expect(a_request(:get, other_host).
with{ |req| req.headers['Accept-Encoding'] != 'unwanted-encoding' }).to have_been_made
end
end

context "when response indicates an overloaded server" do
Expand Down

0 comments on commit 57a00cc

Please sign in to comment.