Chrome与Firefox HTTP Cookie

时间:2018-06-07 17:47:24

标签: javascript express cookies cors httpcookie

我有一个快速应用程序,在nginx后面运行,它将cookie设置为各个域的第三方。

我经过很长一段时间才设法在Firefox中运行,但由于某种原因,Chrome没有运气。

这是我的获取请求:

    const headers = new Headers();
    headers.append('Content-Type', 'text/plain');
    headers.append('Accept', 'application/json');
    fetch(`${url}?n=${cookieName}&c=${cookieValue}`, {
        credentials: 'include',
        mode: 'cors', 
        headers: headers,
      })
      .then((response) => {
        console.log(response);
      })
      .catch((err) => {
        console.error(err);
      });

然后服务器收到此消息并成功回复(网络选项卡中的所有内容都很好),除了没有设置cookie!

router.get('/cookie', (req, res) => {
  res.set({
    'Access-Control-Allow-Origin': req.get('Origin'),
    'Access-Control-Allow-Credentials': 'true'
  });
  res.cookie(req.query.n, req.query.c, { maxAge: 33696000, domain: '.example.org' });
  res.end();
});

根据评论中的建议,以下是标题

请求 Chrome

GET /cmp/cookie?n=euconsent&c=BOO_wcqOO_xMqA0ABBENAk-AAAAXyACABAAGUA HTTP/1.1
Host: pluto.mgr.consensu.org
Connection: keep-alive
accept: application/json
Origin: https://wearemiq.com
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36
content-type: text/plain
Referer: https://wearemiq.com/
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9

请求 Firefox

Accept: application/json
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.5
Connection: keep-alive
content-type: text/plain
Host: pluto.mgr.consensu.org
origin: https://wearemiq.com
Referer: https://wearemiq.com/
User-Agent: Mozilla/5.0 (Macintosh; Intel …) Gecko/20100101 Firefox/59.0

Chrome 中的回复:

HTTP/1.1 200 OK
Server: nginx/1.10.3 (Ubuntu)
Date: Thu, 07 Jun 2018 19:05:14 GMT
Content-Length: 0
Connection: keep-alive
X-Powered-By: Express
Access-Control-Allow-Origin: https://wearemiq.com
Access-Control-Allow-Credentials: true
Set-Cookie: euconsent=BOO_wcqOO_xMqA0ABBENAk-AAAAXyACABAAGUA; Max-Age=33696; Domain=.consensu.org; Path=/; Expires=Fri, 08 Jun 2018 04:26:50 GMT

Firefox 中的响应:

Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: https://wearemiq.com
Connection: keep-alive
Content-Length: 0
Date: Thu, 07 Jun 2018 19:08:28 GMT
Server: nginx/1.10.3 (Ubuntu)
Set-Cookie: euconsent=BOO_xeTOO_xq_A0ABBEN…Fri, 08 Jun 2018 04:30:04 GMT
X-Powered-By: Express

更新: 我删除了所有扩展程序,但有些仍在chrome://net-internals处可见: random

ALSO 一切正常,隐姓埋名,奇怪!

0 个答案:

没有答案