const options = {
follow_set_cookies: true,
cookies: {
test: new Date().valueOf()
}
};
const response = await needle('GET', 'https://setcookie.net/', undefined, options);
console.log(response.body.match(/<code>(.+)<\/code>/i)?.[1]);
const response2 = await needle('GET', 'https://shorturl.at/BQUI3', undefined, options);
console.log(response2.body.match(/<code>(.+)<\/code>/i)?.[1]);
The example can looks strange but in real case it's a redirect from www.host.com to host.com
It was broken in 3.1.0 after had added the challenge host_and_ports_match
|
// if follow_set_cookies is true, insert cookies in the next request's headers. |
|
// we set both the original request cookies plus any response cookies we might have received. |
|
if (config.follow_set_cookies && utils.host_and_ports_match(headers.location, uri)) { |
|
var request_cookies = cookies.read(config.headers['cookie']); |
|
config.previous_resp_cookies = resp.cookies; |
|
if (Object.keys(request_cookies).length || Object.keys(resp.cookies || {}).length) { |
|
config.headers['cookie'] = cookies.write(extend(request_cookies, resp.cookies)); |
|
} |
|
} else if (config.headers['cookie']) { |
|
debug('Clearing original request cookie', config.headers['cookie']); |
|
delete config.headers['cookie']; |
|
} |
#428
The example can looks strange but in real case it's a redirect from
www.host.comtohost.comIt was broken in 3.1.0 after had added the challenge
host_and_ports_matchneedle/lib/needle.js
Lines 542 to 553 in 9454d7b
#428