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

Adding ability to omit User-Agent header #3703

Merged
merged 5 commits into from Mar 29, 2021
Merged

Conversation

@MikeBishop
Copy link
Contributor

@MikeBishop MikeBishop commented Mar 23, 2021

Fixes #3702.

Old behavior:

  • If headers["User-Agent"] (or "user-agent", not repeated hereafter) is falsy or absent, override with the Axios User-Agent string
  • If headers["User-Agent"] is present and truthy, use it

New behavior:

  • If headers["User-Agent"] is absent, override with the Axios User-Agent string
  • If headers["User-Agent"] is present and truthy, use it
  • If headers["User-Agent"] is present and falsy, omit the header

This maintains the existing behavior for any reasonable usage, but enables explicit action to omit the UA header when desired.

lib/adapters/http.js Outdated Show resolved Hide resolved
Loading
@jasonsaayman
Copy link
Member

@jasonsaayman jasonsaayman commented Mar 24, 2021

@MikeBishop please can you add tests for this change?

Loading

Copy link
Member

@jasonsaayman jasonsaayman left a comment

Looks good

Loading

@jasonsaayman jasonsaayman merged commit b0959f0 into axios:master Mar 29, 2021
1 check passed
Loading
mastermatt added a commit to mastermatt/axios that referenced this issue Sep 6, 2021
jasonsaayman added a commit that referenced this issue Sep 7, 2021
* Caseless header comparing in HTTP adapter.

It was adding User-Agent and removing Authorization, but only when
existing headers had the exact right casing. Node uses caseless logic
when managing headers.

This was causing some requests to have `User-Agent` appended to the
headers object and overriding provided agent strings.

Also included is an update to not override the `Content-Length` if it
was already defined in the options. It can be desirable to manually
specify a content length that does not match the data on hand.
Especially for testing.

* Fix eslint error

* fixup: update state UA logic

Play nice with #3703

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
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

2 participants