【问题标题】:How do I set a cookie `Priority=High` in express router?如何在快速路由器中设置 cookie `Priority=High`?
【发布时间】:2020-08-02 12:21:27
【问题描述】:

Chrome 有一个 Cookie 标志 Priority,它优先考虑哪些 Cookie 将首先被删除(优先级较低)..

例如

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

我想从 express 中设置这个值,但无论如何我看不到我会这样做 (docs)。

有人能指出我正确的方向吗? (需要我自己设置header吗?)

参考资料:

【问题讨论】:

标签: express google-chrome cookies http-headers setcookie


【解决方案1】:

所以,我最终只使用 express 内部使用的 cookie 库...

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)

给...

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

【讨论】:

    猜你喜欢
    • 2021-06-26
    • 1970-01-01
    • 1970-01-01
    • 2013-11-16
    • 2017-02-26
    • 1970-01-01
    • 2018-09-27
    • 2016-11-16
    • 2018-03-04
    相关资源
    最近更新 更多