-
Notifications
You must be signed in to change notification settings - Fork 337
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
Cannot set > 1 cookies #106
Comments
Solved case HTTPoison.get("https://httpbin.org/cookies", %{}, hackney: [cookie: "cookie1=1 cookie=2"]) do |
I wonder if we should support the first instead of the one that is working.. |
Yes, I was looking at the test_case and it passes an array to cookie with a tuple in it... This isn't working for me! I will try the second way... And it still doesn't work. Maybe I need to set domain and path on these cookies? |
I tried to set domain and path but without success. The only way for me was to integrate a recall in phantomjs/casperjs, that's not a clean solution but it works. With the second way I got my script working: https://i.imgur.com/bYu0Xvb.png |
Not sure whether someone is still interested in this but it looks like I finally could set several cookies and specify their domain, path and other options. Here is a working example: iex(1)> HTTPoison.get("https://httpbin.org/headers", %{}, hackney: [cookie: [{"foo", "0", [{:path, "/headers"}, {:domain, ".httpbin.org"}, {:secure, true}, {:max_age, 300}]}, {"bar", "1", [{:path, "/"}, {:domain, ".httpbin.org"}]}]])
{:ok,
%HTTPoison.Response{body: "{\n \"headers\": {\n \"Cookie\": \"foo=0; Version=1; Expires=Sat, 14-May-2016 14:05:33 GMT; Max-Age=300; Domain=.httpbin.org; Path=/headers; Secure, bar=1; Version=1; Domain=.httpbin.org; Path=/\", \n \"Host\": \"httpbin.org\", \n \"User-Agent\": \"hackney/1.6.0\"\n }\n}\n",
headers: [{"Server", "nginx"}, {"Date", "Sat, 14 May 2016 14:00:32 GMT"},
{"Content-Type", "application/json"}, {"Content-Length", "263"},
{"Connection", "keep-alive"}, {"Access-Control-Allow-Origin", "*"},
{"Access-Control-Allow-Credentials", "true"}], status_code: 200}} In my opinion, it would be fine to update |
That would be amazing! Could you send a PR updating both? 🎉 |
I've just started playing around with different tests and now it looks like I hurried with the conclusions. It turned out that the above example is not working in HTTParrot and this is the expected behaviour. Actually I was mislead a little by one of the previous comments and the hackney docs: several cookie attributes are described there but according to the latest RFC the client must not send anything but a list of iex(1)> HTTPoison.get!("http://httparrot.herokuapp.com/cookies", %{}, hackney: [cookie: ["foo=1; bar=2"]])
%HTTPoison.Response{
body: "{\n \"cookies\": {\n \"foo\": \"1\",\n \"bar\": \"2\"\n }\n}",
headers: [{"Connection", "keep-alive"}, ...],
status_code: 200
}
iex(2)> HTTPoison.get!("https://httpbin.org/cookies", %{}, hackney: [cookie: ["foo=1; bar=2"]])
%HTTPoison.Response{
body: "{\n \"cookies\": {\n \"bar\": \"2\", \n \"foo\": \"1\"\n }\n}\n",
headers: [{"Server", "nginx"}, ...],
status_code: 200
} Finally, I updated the |
Thanks for the detailed info 👍 |
Cookie headers in HTTP requests are only supposed to have a name and value. Chaperon was previously just echoing back the response cookies that came from the server, which included attributes like `Expires` and `HttpOnly`. When web servers parsed the `HTTP_COOKIE` header it would incorrectly create weird cookies like `HttpOnly` with a null value. https://tools.ietf.org/html/rfc6265 Setting multiple cookies was also broken: the hackney `cookie` option expects 1 cookie string joined with semicolons. It was previously joining them with newlines which would not get parsed correctly by the web server. edgurgel/httpoison#106
Cookie headers in HTTP requests are only supposed to have a name and value. Chaperon was previously just echoing back the response cookies that came from the server, which included attributes like `Expires` and `HttpOnly`. When web servers parsed the `HTTP_COOKIE` header it would incorrectly create weird cookies like `HttpOnly` with a null value. https://tools.ietf.org/html/rfc6265 Setting multiple cookies was also broken: the hackney `cookie` option expects 1 cookie string joined with semicolons. It was previously joining them with newlines which would not get parsed correctly by the web server. edgurgel/httpoison#106
Cookie headers in HTTP requests are only supposed to have a name and value. Chaperon was previously just echoing back the response cookies that came from the server, which included attributes like `Expires` and `HttpOnly`. When web servers parsed the `HTTP_COOKIE` header it would incorrectly create weird cookies like `HttpOnly` with a null value. https://tools.ietf.org/html/rfc6265 Setting multiple cookies was also broken: the hackney `cookie` option expects 1 cookie string joined with semicolons. It was previously joining them with newlines which would not get parsed correctly by the web server. edgurgel/httpoison#106
When I try to set 2 or more cookies I give only the first one
case HTTPoison.get("https://httpbin.org/cookies", %{}, hackney: [cookie: [{"cookie1", "1"} , {"cookie2", "2"}]]) do
{:ok, %HTTPoison.Response{status_code: 200, body: body}} ->
IO.puts body
{_, %HTTPoison.Response{status_code: _, body: _}} ->
# Nothing to do
end
end
(Sorry for eventually mistakes, i cleanup a complex code for write here) :)
The text was updated successfully, but these errors were encountered: