Should fetch pass cookies when following redirects?
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 7.7k
- Forks
- 880
- Avg merge
- 2d 16h
- Merged PRs (30d)
- 68
Description
Software like Postman (if not disabling the cookie jar in the settings) and browser redirects save cookies when they hit a redirect which has a set-cookie header and set them on requests following that redirect by adding a cookie header.
Should Node.js fetch do this too?
When I request the http://localhost:8080/redirect from this code with Postman, it logs the cookie header and in the Postman console you see the cookie was added to the following request. The native fetch that happens in the code doesn't pass the cookie to the /redirect_to url.
import express from 'express';
const app = express();
app.get('/redirect', (req, res, next) => {
res.cookie('test', 'value');
res.redirect('/redirect_to');
});
app.get('/redirect_to', (req, res, next) => {
console.log(`Cookie: ${req.get('cookie')}`);
res.status(200).end();
});
app.listen(8080, async () => {
try {
await fetch('http://localhost:8080/redirect');
await fetch('http://localhost:8080/redirect', {
credentials: 'include'
});
} catch (err) {
console.error(err);
}
});
Here is the minimal reproduction repository:
https://github.com/dsine-de/fetch-redirect-cookies
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the minimal reproduction repository and the fetch calls to /redirect and /redirect_to. Compare the native fetch behavior with the cookie handling described for Postman, then determine the intended redirect-cookie semantics and the tests needed to establish when the behavior is complete.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nodejs
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100