Skip to content

fix(headers): silently skip empty header names instead of throwing#10875

Merged
jasonsaayman merged 4 commits into
axios:v1.xfrom
rkdfx:fix/6959-empty-header-name-skip
May 22, 2026
Merged

fix(headers): silently skip empty header names instead of throwing#10875
jasonsaayman merged 4 commits into
axios:v1.xfrom
rkdfx:fix/6959-empty-header-name-skip

Conversation

@rkdfx
Copy link
Copy Markdown
Contributor

@rkdfx rkdfx commented May 10, 2026

Summary

AxiosHeaders.setHeader threw Error: header name must be a non-empty string whenever an input source contained an empty key. React Native 0.80+ on Android emits such an entry from response.headers, which made every response throw and crash user code. Switch to a silent skip, mirroring parseHeaders -

if (!key || (parsed[key] && ignoreDuplicateOf[key])) {
return;
}

Linked issue

Closes #6959

Changes

  • lib/core/AxiosHeaders.js: replace the empty-name throw in
    setHeader with an early return.
  • tests/unit/axiosHeaders.test.js: cover empty-name handling across
    all three input shapes.

Checklist

  • Tests added or updated (or N/A with reason)
  • Docs / types updated if public API changed (index.d.ts and index.d.cts)
  • No breaking changes (or called out explicitly above)

Summary by cubic

Silently skip empty or whitespace-only header names in AxiosHeaders.setHeader to prevent crashes when platforms emit empty keys (e.g., React Native 0.80+ on Android). Mirrors parseHeaders behavior and fixes #6959.

Description

  • Summary of changes: Replace the throw on empty/whitespace-only header names in AxiosHeaders.setHeader with an early return (no-op).
  • Reasoning: React Native Android can emit an empty-name header, which previously caused responses to throw and crash user code.
  • Additional context: Matches parseHeaders; applies to string keys, plain objects, and Map inputs.

Docs

  • Update /docs/ to note that empty or whitespace-only header names are ignored across string/object/Map inputs, matching parseHeaders.

Testing

  • Added unit tests in tests/unit/axiosHeaders.test.js covering empty and whitespace-only names for string, object, and Map inputs.
  • Asserts no throws, valid headers remain, and object length is 2.

Semantic version impact

  • Patch: bug fix with no API changes; removes unexpected throws without breaking valid usage.

Written for commit a63294d. Summary will update on new commits. Review in cubic

@rkdfx rkdfx requested a review from jasonsaayman as a code owner May 10, 2026 06:57
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 2 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Copy link
Copy Markdown
Member

@jasonsaayman jasonsaayman left a comment

Choose a reason for hiding this comment

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

Two small suggestions are inline; both are non-blocking on their own but flag together. Nice fix overall: leaf-level placement is the right call, and the test matrix across string/object/Map is exactly what this needs.

Comment thread lib/core/AxiosHeaders.js
Comment thread tests/unit/axiosHeaders.test.js
@jasonsaayman jasonsaayman added priority::medium A medium priority commit::fix The PR is related to a bugfix labels May 13, 2026
Copy link
Copy Markdown

@joe345-str joe345-str left a comment

Choose a reason for hiding this comment

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

merge please

@rkdfx rkdfx requested a review from jasonsaayman May 15, 2026 20:04
rkdfx added 2 commits May 20, 2026 21:21
Signed-off-by: Ravi <13908473+rkdfx@users.noreply.github.com>
Signed-off-by: Ravi <13908473+rkdfx@users.noreply.github.com>
@rkdfx rkdfx force-pushed the fix/6959-empty-header-name-skip branch from 8e0546a to 17fadb0 Compare May 20, 2026 15:51
@jasonsaayman jasonsaayman merged commit 278041d into axios:v1.x May 22, 2026
26 checks passed
jasonsaayman added a commit that referenced this pull request May 28, 2026
…10875)

* fix(headers): silently skip empty header names instead of throwing

Signed-off-by: Ravi <13908473+rkdfx@users.noreply.github.com>

* chore: add suggested test headers length assert

Signed-off-by: Ravi <13908473+rkdfx@users.noreply.github.com>

* test(headers): cover whitespace-only header names

---------

Signed-off-by: Ravi <13908473+rkdfx@users.noreply.github.com>
Co-authored-by: Jay <jasonsaayman@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commit::fix The PR is related to a bugfix priority::medium A medium priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[React Native 0.80.1] Header name must be a non-empty string on Android

3 participants