tomas / needle

Nimble, streamable HTTP client for Node.js. With proxy, iconv, cookie, deflate & multipart support.
https://www.npmjs.com/package/needle
MIT License
1.63k stars 236 forks source link

Cookies don't send after redirect #437

Open sheldhur opened 2 months ago

sheldhur commented 2 months ago
  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 https://github.com/tomas/needle/blob/9454d7bdc94b5a9a9c8f60eafefb6408f83a9a37/lib/needle.js#L542-L553

https://github.com/tomas/needle/issues/428

sheldhur commented 2 months ago

@tomas can you(or I?) just remove this challenge or add a callback with the challenge in config? It's wrong because for example SSO usually located an another domain

tomas commented 2 months ago

I'm not sure what the problem is. Feel free to submit a PR (with tests) and I'll be happy to merge it.