-
Notifications
You must be signed in to change notification settings - Fork 1
Description
In addition to headers, IAppResponse must optionally accept array of cookies, where each cookie object can be using type from npm cookies module or from our own interface.
Then must also update responseWriter to send out cookies during response
Create a wrapper class for getting and setting cookies. Then can drop-in concrete implementation using either cookie or cookies npm package.
cookies vs cookie lib: cookies actually is aware of req, res object and can actually get and set cookies
cookie package can only parse and encode cookie and so must set cookie manually using setHeader('Set-Cookie', ....)
Also cookies library has support for signed cookie where cookie package does not.
Both of these throw exceptions all over the place, so must be aware of that and possibly convert to our own exceptions.
cookies package does not seem to attempt to parse encoded cookie in any way, just returns in in raw format.
This is how cookies module works to set cookies
headers = res.getHeader("Set-Cookie") || []
// later it pushed new value to this 'headers' array with value of new cookie
// then it calls setHeader. So in case of multiple calls to set() it will cal setHeader multiple times
// with same header name 'Set-Cookie'
// every time it will first get the value of Set-Cookie header and it would have something set from previous time
// and it will get array of strings... it may splice out previously set string with name of same cookie if override is true in Cookie object.
var setHeader = res.set ? http.OutgoingMessage.prototype.setHeader : res.setHeader
setHeader.call(res, 'Set-Cookie', headers)
So it calls setHeader multiple times with same header name 'Set-Cookie' and it will just override the value (new updated array as a value) so response write will use the latest value of array when it starts to write response.