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

Use case insensitive headers #57

Closed
motss opened this issue Jul 12, 2018 · 13 comments
Closed

Use case insensitive headers #57

motss opened this issue Jul 12, 2018 · 13 comments

Comments

@motss
Copy link

motss commented Jul 12, 2018

const TYPE = 'Content-Type';

According to https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2, HTTP headers are case insensitive. Thus, it should also handle 'content-type'.

@lukeed
Copy link
Owner

lukeed commented Jul 12, 2018

Yo!

So this only matches case-sensitive for the headers you manually provide into the last argument. This is done as I most commonly saw Express developers use capitalized forms in their applications.

Once the helper reaches these two places:

res.setHeader(TYPE, type || OSTREAM);

res.writeHead(code, headers);

... Node automatically lowercases any/all keys it received.

@motss
Copy link
Author

motss commented Jul 12, 2018

Yeah and I happen to be a portion of them who using everything lowercase in all kind of headers.

send(res, 200, { 'content-type': 'application/json' });

It took me quite a while to figure this out until I look at the code. Any plan to resolve this?

@lukeed lukeed closed this as completed in 83731c5 Sep 16, 2018
@lukeed
Copy link
Owner

lukeed commented Sep 17, 2018

Hey @motss, sorry for the delay on this. This will be working for you in the next release 😄

I just lowercased any/all header keys that were passed into send before continuing any logic. If you get a chance to look at it that'd be awesome. Thanks!

@motss
Copy link
Author

motss commented Sep 17, 2018

LGTM! Really appreciate the fix.

@T1MOXA
Copy link

T1MOXA commented Jun 19, 2020

What cat I do if I need to send response with uppercase letters ?

@lukeed
Copy link
Owner

lukeed commented Jun 19, 2020

You should use @polka/send@next :: https://github.com/lukeed/polka/blob/next/packages/send/index.js

It still reads your header values without caring about case, but it will write output headers with capital casing.

You should also fix/report an issue with your HTTP client, because it's supposed to not matter

@T1MOXA
Copy link

T1MOXA commented Jun 20, 2020

obj[k.toLowerCase()] = headers[k];

Makes header key lowercase.

@lukeed
Copy link
Owner

lukeed commented Jun 20, 2020

obj[TYPE] = type || 'text/plain';

@T1MOXA
Copy link

T1MOXA commented Jun 22, 2020

I'm not talking about the content type, I have a problem with custom headers like
{ "Example-Header": "some value" }

@lukeed
Copy link
Owner

lukeed commented Jun 22, 2020

Ah sorry, you didn't specify.

Then I wouldn't include them inside the send object.
Instead you could do res.setHeader('Example-Header', 'value'). It's a little more verbose, but IMO that's the price you should probably have to pay for requiring non-standard/spec'd behavior. Again, whatever is reading your HTTP headers is supposed to be case-insensitive.

@T1MOXA
Copy link

T1MOXA commented Jun 22, 2020

Yes, this is an option, but it would be better if send allowed you to do this without setHeader

@lukeed
Copy link
Owner

lukeed commented Jun 22, 2020

Sorry, I'm really not inclined to support this. I don't want to lock in/promise vanity behavior that shouldn't be there in the first place. Forces Polka to continue that (almost) indefinitely when, again, the HTTP spec says it's not supposed to matter.

@T1MOXA
Copy link

T1MOXA commented Jun 23, 2020

Ок, anyway thanks for reply and cool lib :)

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

No branches or pull requests

3 participants