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

cookie_store not working over redirections #510

Closed
Ten0 opened this issue Apr 28, 2019 · 3 comments · Fixed by #514
Closed

cookie_store not working over redirections #510

Ten0 opened this issue Apr 28, 2019 · 3 comments · Fixed by #514
Labels
C-bug Category: bug. Something is wrong. This is bad! E-easy Effort: Easy! Start here :D

Comments

@Ten0
Copy link
Contributor

Ten0 commented Apr 28, 2019

I'm trying to run a login process through request which involves a lot of redirections.
My client is of course setup with cookie_store(true).

Having looked at the debug logs, it feels like cookies are set when receiving a Set-Cookie header, but that they are not used until the next call to reqwest, that is, the request subsequent to the response that was both a Set-Cookie and a redirect does not have these cookies set.

Can you confirm this behaviour and help me out at properly passing these cookies in that kind of scenario ?

@WindSoilder
Copy link
Contributor

WindSoilder commented Apr 29, 2019

I have got the same issue, then I tried to dive into code and spot the following:

                    match action {
                        redirect::Action::Follow => {
                            self.url = loc;

                            remove_sensitive_headers(&mut self.headers, &self.url, &self.urls);
                            debug!("redirecting to {:?} '{}'", self.method, self.url);
                            let uri = expect_uri(&self.url);
                            let body = match self.body {
                                Some(Some(ref body)) => ::hyper::Body::from(body.clone()),
                                _ => ::hyper::Body::empty(),
                            };
                            let mut req = ::hyper::Request::builder()
                                .method(self.method.clone())
                                .uri(uri.clone())
                                .body(body)
                                .expect("valid request parts");

                            *req.headers_mut() = self.headers.clone();
                            // Add a print message to header to see what's going on..
                            println!("Redirected request: {:?}", req);
                            // End...
                            self.in_flight = self.client.hyper.request(req);
                            continue;
                        }
                        ...
                    }  // end of match

in the async_impl/client.rs (Sorry for the tupid println!, but I don't know how to debug yet =.= )

According to the print message, I find that the redirected request doesn't contains Cookie header.

@Ten0
Copy link
Contributor Author

Ten0 commented Apr 29, 2019

That doesn't seem very hard to fix, we should have access to cookie_store from there :)

@seanmonstar seanmonstar added C-bug Category: bug. Something is wrong. This is bad! E-easy Effort: Easy! Start here :D labels Apr 29, 2019
@seanmonstar
Copy link
Owner

Excellent work digging through, @WindSoilder!

It appears the fix here involves these steps:

  • Checking the cookie_store in the redirect::Action::Follow case.
  • Adding a test to tests/redirect.rs.

If anyone wish to take a stab an open a PR, I can help direct the effort!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug. Something is wrong. This is bad! E-easy Effort: Easy! Start here :D
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants