jshttp / vary

Manipulate the HTTP Vary header

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

abstract even more into an "append-header" module

jonathanong opened this issue · comments

there's https://github.com/tellnes/append-header/blob/master/index.js but i dunno.

was looking to implement this in express and koa. realized TJ already thought of this: https://github.com/koajs/koa/blob/master/lib/response.js#L404. an append header module would probably more appropriate since we have to handle cookies and stuff as well.

No. That append-header module does not work right, and with Vary we want to "append to header" not "append header". There is a big difference between those two. Appending a header means to literally add another Header: blah line in the HTTP response, while appending to header means to add another value to the same Header: blah line in the HTTP response.

TD;DR both of those links are not "append-header" they are "append-to-header". This is an actual append header: https://github.com/senchalabs/connect/blob/2.x/lib/patch.js#L95

We could make an append-to-header module, though.

I see that in the koa one, TJ does specifically document the method as "Append val to header field." i.e. it's documented as the "append-to-header" it is, since it is not an "append-header".

And unfortunately we can't make at least this module any smaller, otherwise we cannot adhere to RFC 2616 Vary requirements without even more work.

We could make a module that does both: append header and append to header. We could also have that module keep a list of different headers that have different behaviors, like "Warning" header must be different full header lines, not comma-separated; "Content-Type" cannot occur more than once; "Content-MD5" cannot occur more than once and also cannot even be appended to, etc.

sooo many abstractions oh gosh

sooo many abstractions oh gosh

lol. I'm OK with then as long as they are useful and actually adhere to the specifications they are purporting to abstract.

For example, what I like about this vary module is that it makes it easy for middlewares that vary the response based on a header field to say so, since they don't have to understand RFC 2616 fully (specifically the handling of the * value) and they don't have to understand how to update a header from node.js core res.getHeader (since it could be undefined, a string, or an Array).

👍 I get the reasoning, not saying we shouldn't XD

So, yet another problem, is that if this other append module were to want to prevent duplicate values, it would need to be told how to do that. Some things (like Vary) contain case-insensitive data, but others (like Set-Cookie in your example) are case-sensitive.

Basically this module would have to be a bit full-featured, but it's doable. @jonathanong are you interested in building this module, or should I with my RFC-love do it (:D)?

hmmm i didn't realize it would be so complicated. up to you!

i'm going to close this because i think it's pointless. just create a new lib if you disagree :D