0

Chrome has a Cookie flag Priority which prioritises which Cookies will be deleted first (lower priority)..

e.g.

Set-Cookie: GAPS=1:ZYBtVMzURzU2umKMxZThJ2lVPxy3Hg:SvHhlG2k1Vy5pnA0;Path=/;Expires=Wed, 04-Nov-2015 20:44:37 GMT;Secure;HttpOnly;Priority=High

I'd like to set this value from express, but I can't see anyway I'd do that (docs).

Can someone point me in the right direction? (Do I need to set the header myself?)

References:

Nick Grealy
  • 24,216
  • 9
  • 104
  • 119
  • just pass it to options, see the source on how its set https://github.com/expressjs/express/blob/0a48e18056865364b2461b2ece7ccb2d1075d3c9/lib/response.js#L857 – Lawrence Cherone Apr 20 '20 at 04:17
  • Thanks @LawrenceCherone, but unfortunately the `cookie` library doesn't just take arbitrary options... see here -> https://github.com/jshttp/cookie/blob/master/index.js#L101-L182 – Nick Grealy Apr 20 '20 at 05:39
  • np, sorry didn't delve into that lib, just presumed it `join('; ')`'ed it, would be an easy PR – Lawrence Cherone Apr 20 '20 at 13:59

1 Answers1

1

So, I ended up just using the cookie library internally used by express...

const cookie = require('cookie')

// ... inside route ...

let setCookie = cookie.serialize('name', value, {
  expires: new Date(9999, 11, 31),
  path: '/',
  httpOnly: true,
  secure: true,
  domain: yourCookieDomain
})
setCookie += '; Priority=High'
res.append('Set-Cookie', setCookie)

Gives...

set-cookie: name=value; Domain=foobar.com; Path=/; Expires=Fri, 31 Dec 9999 00:00:00 GMT; HttpOnly; Secure; Priority=High

Nick Grealy
  • 24,216
  • 9
  • 104
  • 119