Return first value in the internal array when calling Response.get() or something? #97
Unanswered
BobbyWibowo
asked this question in
Q&A
Replies: 1 comment 1 reply
-
I see, so I have a plan for a major overhaul of the compatibility methods. Essentially my plan is to first support all compatibility methods/properties from Node's native I've been focusing my last few updates on performance and implementing features from uWebsockets.js but compatibility is my next roadmap target. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
This is related to my previous discussion about
Response
's.set()
/.header()
actually only keeping last value in #88It appears said behavior is because in ExpressJS, every calls to
.set()
/.header()
will directly callhttp.ServerResponse.setHeader()
, which will always overwrite existing headers with the same nameshttps://github.com/expressjs/express/blob/4.18.1/lib/response.js#L776-L801
https://nodejs.org/docs/latest-v16.x/api/http.html#responsesetheadername-value
So when using
http.ServerResponse.setHeader()
directly with multipleSet-Cookie
headers, you're supposed to set the value into an array of strings, to instructhttp
to later split them into multipleSet-Cookie
headers for network transmission (meaning before the Response is finalized, their values will still be kept as-is)That applies to any header names if their values are arrays, not just
Set-Cookie
And thus ExpressJS's
.cookie()
will instead call an internal.append()
, that merely gets previously set value/array to concat into, before then re-applying the new array into the header namehttps://github.com/expressjs/express/blob/4.18.1/lib/response.js#L854-L887
https://github.com/expressjs/express/blob/4.18.1/lib/response.js#L744-L756
As for ExpressJS's
.get()
, it is merely a direct call tohttp.ServerResponse.getHeader()
https://github.com/expressjs/express/blob/4.18.1/lib/response.js#L811-L813
And since headers values are being kept as-is before being finalized, during normal non-cookies use case, you'd expect them to return the string values as-is (or number, etc., or even array of something, depending on how you previously set them)
I'm not sure what's the best way to align the behavior of current hyper-express' codes aside from just refactoring the headers system,
thus my lazy idea in the discussion title
Beta Was this translation helpful? Give feedback.
All reactions