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

Content-Encoding with multiple encodings not supported #1441

Closed
jbramleycl opened this issue Sep 17, 2018 · 1 comment · Fixed by #1442
Closed

Content-Encoding with multiple encodings not supported #1441

jbramleycl opened this issue Sep 17, 2018 · 1 comment · Fixed by #1442

Comments

@jbramleycl
Copy link
Contributor

It is possible for a server to respond with a Content-Encoding header like:
Content-Encoding: deflate, deflate

From RFC7231:

If one or more encodings have been applied to a representation, the
sender that applied the encodings MUST generate a Content-Encoding
header field that lists the content codings in the order in which
they were applied.

This can be tested with:

def test_multiple_content_encodings():
    data = zlib.compress(zlib.compress(b'foo'))
    fp = BytesIO(data)
    r = HTTPResponse(fp, headers={'Content-Encoding': 'deflate, deflate'})
    assert r.data == b'foo'

Would it make sense to do something like:

if len(self.headers.get('content-encoding').split(',') > 1:
    self._decoder = MultiDecoder(self.headers.get('content-encoding'))

where MultiDecoder just iterates through the list applying standard decoders?

@sethmlarson
Copy link
Member

TIL that Content-Encoding allows for nested encodings. Do you have an example site that does this? We haven't hit this problem until now.

I'm open to a PR that implements this behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants