New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
request.defaults() doesn't always preserve headers and cookie jar #1581
Comments
@RaceProUK more thorough example would be great 👍 |
As requested; I've stripped out stuff that's irrelevant from both snippets. This is where we're creating the initial var jar = request.jar(),
browser = request.defaults({
rejectUnauthorized: false,
jar: jar,
headers: {
'X-Requested-With': 'XMLHttpRequest',
'User-Agent': 'UserAgent'
}
}); And this is where we're trying to add a new header: browser = browser.defaults({
headers: {
'X-CSRF-Token': csrf
}
}); By the documentation, We've been able to work around it by doing this: browser = browser.defaults({
headers: {
'X-Requested-With': 'XMLHttpRequest',
'User-Agent': 'UserAgent',
'X-CSRF-Token': csrf
},
jar: jar
}); Which works, but obviously we'd rather not duplicate code if we can help it 😉 The version of |
Thanks, here is what I'm testing with: var jar = request.jar(),
browser = request.defaults({
rejectUnauthorized: false,
jar: jar,
headers: {
'X-Requested-With': 'XMLHttpRequest',
'User-Agent': 'UserAgent'
}
});
browser = browser.defaults({
headers: {
'X-CSRF-Token': 'csrf'
}
});
browser('http://requestb.in/ougkjpou', function (err, res, body) {
if (err) console.log(err)
console.log(res.statusCode)
}) Is that the correct result? I'm looking at the headers. |
The headers are there alright; not sure why I'm seeing different results… Maybe it's because we're using var jar = request.jar(),
browser = request.defaults({
rejectUnauthorized: false,
jar: jar,
headers: {
'X-Requested-With': 'XMLHttpRequest',
'User-Agent': 'UserAgent'
}
});
browser.get(getUrl, callback);
//other stuff goes on; eventually getting to this bit
browser = browser.defaults({
headers: {
'X-CSRF-Token': 'csrf'
}
});
browser.post(postUrl, body, callback); |
Ok, I was able to reproduce it, probably that's a bug, I'll take a look at it. |
Ok, this was fixed in #1540 but it's not published to NPM yet :) |
Closing @RaceProUK this fix will be released when 2.56 is published on NPM |
According to the documentation,
specialRequest
should send both thex-token
andspecial
headers. However, this isn't always the case; sometimes, it only sends thespecial
header. Similarly, the cookie jar, if one is being used, gets unassigned.I can provide a more concrete example if required.
The text was updated successfully, but these errors were encountered: