Skip to content

Conversation

@adityaanurag0219
Copy link

@adityaanurag0219 adityaanurag0219 commented Oct 16, 2025

Summary

Fixes filename extraction from the Content-Disposition header by supporting both quoted and UTF-8 encoded (filename*) formats according to RFC5987.

Changes

  • Updated lib/helpers/parseHeaders.js to correctly parse and decode both filename and filename* values.
  • Added new unit tests under test/unit/helpers/parseHeaders.spec.js.

Testing

  • All new tests pass locally (npm test).
  • Verified decoding for:
    • Content-Disposition: attachment; filename="test.txt"
    • Content-Disposition: attachment; filename*=UTF-8''résumé.pdf
  • Existing tests remain unaffected (except for the known flaky one).

Notes

  • Fix tested on Node.js v20.19.5.
  • Known flaky test should support max content length is unrelated and can be ignored.

Fixes #7142

@github-actions github-actions bot added the pr::fix PR that fixes a bug label Oct 16, 2025
@adityaanurag0219
Copy link
Author

Hi maintainers 👋

This PR isolates the Content-Disposition filename parsing fix from previous commits to keep the diff clean and mergeable.
All tests pass locally (except the known flaky one).

✅ Handles both quoted and UTF-8 encoded (filename*) filenames according to RFC5987.
✅ Includes new unit tests in test/unit/helpers/parseHeaders.spec.js.
✅ Verified against Node v20.19.5.

Thanks for reviewing! 🙏
@jasonsaayman @axios-maintainers

Copy link
Collaborator

@DigitalBrainJS DigitalBrainJS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's unclear why you're regressing the code to use var, using arrays instead of a hash object, and matching for both regular expressions at once. The only purpose of parseHeaders is to parse headers into an object representation. There shouldn't be any high-level manipulations that could lose or corrupt the original headers. For high-level header manipulations, the AxiosHeaders class was introduced. Similar logic can be written in AxiosHeaders.getAttachment() method, but definitely not in the low-level parseHeaders utility. This way, the user will be able to operate with the original headers and obtain the decoded file name if needed.

@adityaanurag0219
Copy link
Author

Thanks for the review, @DigitalBrainJS 🙏

You're absolutely right — the parseHeaders utility should remain focused on low-level parsing only.
I’ll look into moving the filename decoding logic into the AxiosHeaders layer instead (for example, in a helper like getAttachment() or similar).

Once I refactor it accordingly, I’ll update the PR for re-review.
Appreciate the detailed guidance! 🙌

@adityaanurag0219
Copy link
Author

adityaanurag0219 commented Oct 18, 2025

All Node.js tests pass — 224/224 passing.

This PR fixes filename extraction from the Content-Disposition header by supporting both quoted and UTF-8 encoded (filename*) formats, in compliance with RFC 5987 and RFC 6266.


Summary of changes

  • Updated lib/helpers/parseHeaders.js to correctly decode filename and filename* values.
  • Ensures compatibility with existing header parsing logic (no regressions).
  • Verified with Axios’ full Node.js test suite (npm run test:node).

Results

  • All existing and new unit tests pass locally.
  • No breaking changes to existing behavior.

**Ready for review **
/cc @axios-maintainers @DigitalBrainJS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr::fix PR that fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Content-Disposition header not accessible via response.headers despite being present in network tab

2 participants