Skip to content

DownloadLengthMismatchError because requests automatically decodes gzip files #2047

@dennisvang

Description

@dennisvang

Description of issue or feature request:

If target is a gzip file, served with a Content-Encoding: gzip header, requests will automatically decode the file.

Current behavior:

As a result, the default fetcher for tuf ngclient raises a DownloadLengthMismatchError:

tuf.api.exceptions.DownloadLengthMismatchError: Downloaded x bytes exceeding the maximum allowed length of y

Expected behavior:

From the requests docs:

An important note about using Response.iter_content versus Response.raw. Response.iter_content will automatically decode the gzip and deflate transfer-encodings. Response.raw is a raw stream of bytes – it does not transform the response content. If you really need access to the bytes as they were returned, use Response.raw.

I would expect tuf to access the Reponse.raw instead of Response.iter_content here:

for data in response.iter_content(self.chunk_size):

Note that Response.raw is a urllib3.response.HTTPResponse, which also decodes gzip encoded content by default, but requests disables this by setting decode_content=False.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions