Skip to content

Decode extended filenames for streamed downloads - #398

Open
saitakarcesme wants to merge 1 commit into
requests:masterfrom
saitakarcesme:codex/extended-download-filenames
Open

saitakarcesme wants to merge 1 commit into
requests:masterfrom
saitakarcesme:codex/extended-download-filenames

Conversation

@saitakarcesme

Copy link
Copy Markdown

Downloads with a Content-Disposition filename* parameter currently fail to infer a filename. Decode the declared charset and percent escapes, prefer a valid extended filename over the ordinary fallback regardless of order, and strip directory components after decoding. Malformed encodings fall back to filename.

Fixes #379. Follows RFC 6266 section 4.3.

Added coverage for UTF-8, ISO-8859-1, language tags, parameter casing, precedence, malformed values, encoded path separators/drive prefixes, and writing the downloaded content to the inferred Unicode filename. Nine regressions failed before implementation.

Validation:

  • Python 3.13: 184 passed, 5 skipped.
  • Python 3.11 with pyOpenSSL 24.0.0: 184 passed, 5 skipped with deprecation warnings treated as errors. Newer pyOpenSSL triggers existing X509 adapter deprecations under that strict setting.
  • Package flake8 and git diff --check pass. The test file retains two pre-existing style findings on unchanged lines.
  • Sphinx HTML build succeeds with an existing theme deprecation warning.
  • Python 2.7 is not available locally; the existing compatibility style is retained but that interpreter was not tested.

Disclosure: implemented and tested using OpenAI Codex in an authorized automated contribution session.

Honor encoded Content-Disposition filename parameters when inferring a
download path, including fallback and directory stripping after decoding.

Closes requests#379
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 this pull request may close these issues.

requests_toolbelt.downloadutils can not parse encoded file name in response header

1 participant