Polka: Use case insensitive headers

Created on 12 Jul 2018  路  13Comments  路  Source: lukeed/polka

All 13 comments

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:

https://github.com/lukeed/polka/blob/a9f0f583d848f1169d07bc89e5c630db6a76452e/packages/send-type/index.js#L10

https://github.com/lukeed/polka/blob/a9f0f583d848f1169d07bc89e5c630db6a76452e/packages/send-type/index.js#L26

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

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?

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!

LGTM! Really appreciate the fix.

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

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

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

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.

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

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._

袨泻, anyway thanks for reply and cool lib :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

orefalo picture orefalo  路  6Comments

fanatid picture fanatid  路  5Comments

lukeed picture lukeed  路  10Comments

flawyte picture flawyte  路  7Comments

charleslxh picture charleslxh  路  3Comments