Skip to content
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

missing cookie header on redirect #40

Closed
onldosalm opened this issue Oct 8, 2013 · 3 comments
Closed

missing cookie header on redirect #40

onldosalm opened this issue Oct 8, 2013 · 3 comments

Comments

@onldosalm
Copy link

Hello...
I am Heepan Kim.

First of all, thank you for sharing your code.

Original source code line 208

// if redirect code is found, send a GET request to that location if enabled via 'follow' option
if ([301, 302].indexOf(resp.statusCode) != -1 && headers.location) {
  if (count <= config.follow)
    return self.send_request(++count, 'GET', url.resolve(uri, headers.location), config, null, callback);
  else if (config.follow > 0)
    return callback(new Error('Max redirects reached. Possible loop in: ' + headers.location));
}

This code not working on cookie based server.

So I suggest my code.

// if redirect code is found, send a GET request to that location if enabled via 'follow' option
if ([301, 302].indexOf(resp.statusCode) != -1 && headers.location) {
  if (count <= config.follow) {
    // --------------------------------------------------
    // must set cookie
    var cookies = headers['set-cookie'];
    if ( cookies ) {
      config.base_opts.headers.Cookie = cookies[0];
    }
    // --------------------------------------------------
    return self.send_request(++count, 'GET', url.resolve(uri, headers.location), config, null, callback);
  }
  else if (config.follow > 0)
    return callback(new Error('Max redirects reached. Possible loop in: ' + headers.location));
}
@tomas
Copy link
Owner

tomas commented Oct 8, 2013

Hi, needle does not support cookies (yet), but feel free to fork away and do a pull request. I'm not sure if this code should go in the redirect logic, though.

@tomas tomas closed this as completed Oct 8, 2013
@onldosalm
Copy link
Author

IBM Lotus Domino system, the user authentication is handled with cookies.

If authentication is successful, the status value is HTTP 302 Redirection and 'LTPAToken' cookies returns.
If authentication fails, an HTTP 200 OK and no cookies.

I am currently certified to the proposed code is handled well, it redirects are processed normally.

@haohcraft
Copy link

Thanks @kheepan !!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants