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

Headers should be compared with case ignored #1237

Closed
betalb opened this issue Dec 13, 2017 · 7 comments
Closed

Headers should be compared with case ignored #1237

betalb opened this issue Dec 13, 2017 · 7 comments

Comments

@betalb
Copy link

betalb commented Dec 13, 2017

Summary

Headers provided in config are merged with defaults without checking for existing value that can be in different case

i.e. when doing below request we can't predict which value will be set from defaults Accept or from config accept

axios.request(url, {
  headers: {
    accept: 'some-accept-value'
  }
});

Chrome will set Accept, which is not expected

Context

  • axios version: 0.17.0
  • Environment: node v9.2.1, chrome 63, macOS
betalb added a commit to betalb/axios that referenced this issue Dec 13, 2017
@betalb
Copy link
Author

betalb commented Dec 13, 2017

I've created potential fix, if it looks good, I can adopt to contributing guide, and create PR

betalb@09cbfdc

@robaxelsen
Copy link
Contributor

@betalb I would propose you submit your PR directly, as it's easier for the maintainers to notice it and potentially approve it.

@montogeek
Copy link

@betalb Please submit the PR, What you think about using a Map?

@betalb
Copy link
Author

betalb commented Jan 12, 2018

Will create PR shortly, need to write failing test first.

@montogeek about map, we need case insensitive map in this case, which is not offered by ES spec. And I don't see how map will help here, IMHO it will just add more confusion. Even if we will be able to predict in which order keys will be iterated, it won't help library user a lot, as he will need to know how adapter is implemented (maybe adapter is sorting headers by key) and which default values are provided by axios.

I was trying not to increase the size of library itself too much. Trade off was made and merge method became case-insesnistive merge (that also does whitespace trimming of keys), which should be OK for it's current use case.

@betalb
Copy link
Author

betalb commented Jan 14, 2018

I've raised PR, anyone interested please review

@codeclown
Copy link
Contributor

IMO the most straight-forward way would be to lowercase all header names (a) in defaults, and (b) when headers are passed to instance/request. Only dealing with lowercase header names would remove any fiddling around which case to check.

@jasonsaayman
Copy link
Member

Hi,

Thank you for this pull request, this is a pretty stale pull request so I am going to close this in favour of #2880 as its a bit fresher and seems to solve the asme issue. If you feel it does not solve this issue please open an issue again.

Thanks

@axios axios locked and limited conversation to collaborators May 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants