简体   繁体   中英

Set-Cookie header not being sent

I am learning how to handle cookies with node.js and express and I encountered a rather peculiar problem. My cookie.js file looks like this:

var router = require('express').Router();

router.get('/cookie/', function(req, res) {
    res.append('Set-Cookie', 'foo=bar').cookie('hi', 'hello').status(200).json([]);
});

module.exports = router;

The problem is that the server is not sending the Set-Cookie header. However, if I modify Set-Cookie to Set-Cookiie then the header is sent (albeit not as a cookie).

I also tried to use res.cookie('hi', 'hello') after requiring and using CookieParser in my server.js and no cookie header is being sent. Why is this happening? Are any other packages (I have a few other packages) interfering with my headers?

Additional Information: I have HTTP running at :80 at HTTPS at :443 (self-signed) and the cookie problem persists in both connections.

I believe that with Postman in order to catch cookies and sessions , you have to install a little add-on Postman Interceptor :

https://chrome.google.com/webstore/detail/postman-interceptor/aicmkgpgakddgnaphhhpliifpcfhicfo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM