Skip to content

Commit 11abbca

Browse files
authored
Merge pull request #9267 from puppetlabs/backport-9265-to-7.x
[Backport 7.x] Remove Accept-Encoding header on redirect
2 parents 0165f44 + d02a4a5 commit 11abbca

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

lib/puppet/http/redirector.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ def redirect_to(request, response, redirects)
5454
next if header.casecmp('Authorization').zero? && request.uri.host.casecmp(location.host) != 0
5555
next if header.casecmp('Cookie').zero? && request.uri.host.casecmp(location.host) != 0
5656
end
57+
# Allow Net::HTTP to set its own Accept-Encoding header to avoid errors with HTTP compression.
58+
# See https://github.com/puppetlabs/puppet/issues/9143
59+
next if header.casecmp('Accept-Encoding').zero?
60+
5761
new_request[header] = value
5862
end
5963

spec/unit/http/client_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,17 @@ def redirect_to(status: 302, url:)
820820
response = client.get(https)
821821
expect(response).to be_success
822822
end
823+
824+
it "does not preserve accept-encoding header when redirecting" do
825+
headers = { 'Accept-Encoding' => 'unwanted-encoding'}
826+
827+
stub_request(:get, start_url).with(headers: headers).to_return(redirect_to(url: other_host))
828+
stub_request(:get, other_host).to_return(status: 200)
829+
830+
client.get(start_url, headers: headers)
831+
expect(a_request(:get, other_host).
832+
with{ |req| req.headers['Accept-Encoding'] != 'unwanted-encoding' }).to have_been_made
833+
end
823834
end
824835

825836
context "when response indicates an overloaded server" do

0 commit comments

Comments
 (0)