Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Accept-Encoding header on redirect #9265

Merged
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
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
Loading