-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Cookies lost during multiple redirects #1502
Comments
Hey @nijikokun can you give me more details. What were the domains and protocols of the redirects? Thanks. |
Hey @lalitkapoor Can't give the domains as they are internal, should work with any, protocol was Cookie type was: |
thanks! Will look into it. If it's not too much trouble could you create a failing test? |
I tried with node Is it possible to get the first redirect response rather than the final response? |
@anklos you could set request to not follow redirects and do the redirect manually, in which case you could get the first response. |
@lalitkapoor thanks. I just did a test with |
Cookies are not passed with redirects
|
@anklos can you tell me if the domains are different? |
I don't need the exact domains, just need to know if they're the same...if one is a subdomain, etc. |
they are on the same subdomain. |
@anklos are you able to modify the cookie on the servers? or do you not have access to do that. I'd like to try something: setting the domain value on the cookie to the hostname (w/subdomain). @nijikokun do your cookies have the domain value set on them? |
@lalitkapoor no I dont. but I can try to set up a https server myself to test the cookie behavior. |
although still not make sense to me why browser could get the |
Just find that I can get Also tried other language http libraries to do the same test, the results are the same as nodejs |
@nijikokun does the above satisfy the concern? |
For me yes On Fri, Apr 3, 2015 at 9:06 PM, Lalit Kapoor notifications@github.com
|
Having similiar problem with redirection cookie, I use the following code to extract cookie on first redirection: var httpreq = {
...
jar: cookieJar
};
request(httpreq, function (error, response, body) {
if (typeof response.headers["set-cookie"]!='undefined') {
response.headers["set-cookie"].forEach(function(aCookie)
{
cookieJar.getCookieString(aCookie);
});
}
}); |
@lalitkapoor I seem to be having this issue on 2.61.
When I turn on
I imagine that the third log output should have my cookies in them. The line where this is logged can be found here. Also, it's good to note here that I am using So in request that are not redirects that third line looks a little bit like this:
|
@Freyert Thanks for the details. I'm traveling this week, but will be able to look at it this weekend, please feel free to remind me. |
@lalitkapoor Thanks! I'll keep taking notes as I explore. |
As an extra note: It seems odd that the third Placing a debugger on this line. Discovery A: Every
|
Hi @lalitkapoor, I have a very similar issue when dealing with requests that contains redirection in response. I have set when testing in Postmanwhen using Requestso I use this code to do the request: var request = require("request");
require('request-debug')(request);
var options = { method: 'POST',
url: 'something hidden',
qs:
{
//something hidden
},
followRedirect: false,
jar: true,
headers:
{ 'postman-token': '48a42acc-3fa4-3c3e-e826-34e6deb26b09',
'cache-control': 'no-cache',
host: 'hidden again',
referer: 'hidden, sorry' } };
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
console.log(response.headers)
}); and the console log of
so you see, the |
+1 |
+1, once the website that I need to access blocks the connection when you don't have cookies from the redirect, I can't access the page. |
@leonardean @jeffreyleeon @patricknn Can you look at |
+1 |
+1 - this seems to be a problem with other headers (e.g., Is the only current workaround to set |
AFAIK yes |
+1 |
1 similar comment
+1 |
I found a workaround by using |
@avadhpatel can you add some psuedocode on how you would handle the callback? |
Sure:
|
@avadhpatel yea, that doesn't work too well because to follow redirects, you should be stripping out the 'set-cookie' header in the response headers. As you can see in your example, there is no object passed to the callback. I don't think the 'this' object is referring to the response....seems weird to me. |
@jmmclean 'this' object in the function is actually the request object. The |
The comment from @jazarja worked for me. const that = this;
if (r.headers.hasOwnProperty('set-cookie')) {
r.headers['set-cookie'].forEach(function(aCookie) {
that._request.options.jar.setCookie(aCookie);
});
} |
+1 |
+1 |
not fixed |
not fixed yet |
+1 |
+1 I can't use postman for our cross-domain authentication because of this, it's a showstopper for me. |
I have the same issue , i didn't get all of the cookies from request module. As you can see i have set
and it worked for me. |
+1 |
Can I make a suggestion? Why not return an array of responses when using |
I have multiple redirects in my case (not just one redirect, there are 3 redirects happen when I access a URL). I have tried all the suggestions above, but without success. Can anyone share manual handling of redirects code and retrieving the cookies? Thanks. |
@lalitkapoor was this ever tackled? And is it being worked on? I think this looks similar to what's being done with the authorization header in line 72 for 401 redirects. Haven't done too much nodejs patching; but would be happy to send up a PR if I manage to fix it. Update: I thought I had this issue but then I've added |
@jonmifsud 👍 using |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
The text was updated successfully, but these errors were encountered: