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

fix the redirections with SetCookie, if the domain is consistent. #73

Closed
wants to merge 2 commits into from

Conversation

ptrsxu
Copy link

@ptrsxu ptrsxu commented Apr 1, 2017

if we access http://www.httpbin.org/cookies/set?k2=v2&k1=v1 with the GET method, the server would return a 302 FOUND with

Location:/cookies
Server:gunicorn/19.7.1
Set-Cookie:k1=v1; Path=/
Set-Cookie:k2=v2; Path=/

in response header, the next request should have the cookie k1=v1 and k2=v2 with it if the redirected location has the same domain with the referer, and finally we can get a content with:

{
  "cookies": {
    "k1": "v1", 
    "k2": "v2"
  }
}

This pull request will fix the problem.


if loc.domain() == url.domain() {
if let Some(&SetCookie(ref cookies)) = res.headers.get::<SetCookie>() {
headers.set(Cookie(cookies.iter().map(|c| c.to_owned()).collect::<Vec<String>>()));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should mean that the sent Cookie headers will contain all the attributes from the Set-Cookie header, aka we'd be sending Cookie: foo=bar; Path=/; Domain=foo.bar; Expires=123, when it should just be Cookie: foo=bar.

Additionally, we could be sending cookies incorrectly. The Path and Domain of the set cookie could possibly not match the new location.

All this logic is tricky to get correct, but it is a goal of reqwest to do it. See #14.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I check it again and the idea is indead half-baked , I would go deeper into it.

@ptrsxu ptrsxu closed this Apr 5, 2017
repi pushed a commit to EmbarkStudios/reqwest that referenced this pull request Dec 20, 2019
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

Successfully merging this pull request may close these issues.

2 participants