Skip to content

Use lowercase headers #990

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

Merged
merged 1 commit into from
Nov 23, 2022
Merged

Conversation

HiiiiD
Copy link
Contributor

@HiiiiD HiiiiD commented Nov 15, 2022

Changes

What does this PR change? Link to any related issue(s).

Undici returns headers in lowercase as it can be seen here. This PR updates the content-type check in order to use the lowercase version.

How to Review

How can a reviewer review your changes? What should be kept in mind for this review?

Checklist

  • Unit tests updated
  • README updated
  • examples/ directory updated (if applicable)

@drwpow
Copy link
Contributor

drwpow commented Nov 16, 2022

Does this fix a problem? I’m not sure why this is needed

@HiiiiD HiiiiD mentioned this pull request Nov 16, 2022
3 tasks
@timothymctim
Copy link

This would fix an issue for me: my backend server sends the Content-Type header in lower case. Since key indices in JavaScript are case sensitive, this would fix it for me, but this fix would break the code for others as it wouldn’t match Content-Type any more. The following code would normalize the header key first before selecting and using it.

let contentType = res.headers[Object.keys(res.headers).find(key => key.toLowerCase() === 'content-type')]
contentType = Array.isArray(contentType)
    ? contentType[0]
    : contentType;

@HiiiiD
Copy link
Contributor Author

HiiiiD commented Nov 18, 2022

As I said in the first PR comment, Undici returns all headers in lowercase, so that's not an issue @timothymctim

@timothymctim
Copy link

timothymctim commented Nov 18, 2022

As I said in the first PR comment, Undici returns all headers in lowercase, so that's not an issue @timothymctim

Indeed, that’s the case! Sorry, my bad :)

@drwpow drwpow merged commit e335c76 into openapi-ts:main Nov 23, 2022
@drwpow
Copy link
Contributor

drwpow commented Nov 23, 2022

@all-contributors please add @HiiiiD for code, test

@allcontributors
Copy link
Contributor

@drwpow

I've put up a pull request to add @HiiiiD! 🎉

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

Successfully merging this pull request may close these issues.

3 participants