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

Unset default application/json content-type header #1362

Closed
Exomnius opened this issue Apr 4, 2018 · 4 comments · Fixed by #1560
Closed

Unset default application/json content-type header #1362

Exomnius opened this issue Apr 4, 2018 · 4 comments · Fixed by #1560

Comments

@Exomnius
Copy link

Exomnius commented Apr 4, 2018

I'm using superagent to perform various request to custom API's for my project. I also want to use it to call the geocode API from google maps. This API only accepts requests without the content-type header due to CORS.

Is it possible to remove (unset) the default application/json type/header? (request-base.js - line 593)

@kornelski
Copy link
Contributor

That's a good use case. We have unset(), which currently only unsets headers you've set() yourself, but it would make sense to keep note which headers have been unset and avoid setting default ones.

@kornelski
Copy link
Contributor

Could you try implementing it? I think it could go like this:

  • in unset save all header names that have been unset, something like `this._unsetHeaders[name] = true (keep in mind case-insensitivity, so lowercase names)
  • in places where we set our own headers (lots in end() and friends) check for _unsetHeaders headers and don't set defauts if the name is set
  • write a test for it.
  • I'm not sure what should happen for .unset(foo).set(foo) combo. maybe it doesn't need special handling?

@Exomnius
Copy link
Author

Exomnius commented Apr 6, 2018

Will do!

@niftylettuce
Copy link
Collaborator

v5.3.0 published to npm and GitHub releases page with changelog

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

Successfully merging a pull request may close this issue.

3 participants