On 4月16日, 午後2:01, Mike Scott <
m...@plokta.com> wrote:
> I've found a fix for my third problem below, which definitely looks like a
> bug in Express.
>
> If I'm setting my own cookie values, then there are two different occasions
> in a single response where res.setHeader is called for a Set-Cookie header,
> once in Express's response.js (line 280) to set my cookie value, and then
> again in Connect's session.js (line 230) to set the session cookie value.
> Node doesn't like you defining the same header twice in a single response --
> according to the Node docs you're supposed to put the two values in an array
> and then call res.setHeader once with the header name and the array.
>
> My fix is that in response.js I don't call res.setHeader, but just save the
> cookie value for later processing, and then in session.js I set both cookies
> at once, if required. But that means changing part of Connect, so I don't
> know if it's a viable fix for Express.
>
> The second problem is fixed; I just needed to add "cookie: {expires: false
>
> }" to the properties of express.session in the config.
>
> The first problem also looks like an Express bug, but can be worked around
> by using:
>
> res.cookie('<cookie name>', '', {expires: new Date(1), path: '/' });
>
> instead of:
>
> res.clearCookie('<cookie name>');
>
> Mike Scott
>