1

Ok, so my new problem in Elixir is that I can't set the explicit domain while creating cookies.

In this case:

HTTPoison.get("httpbin.org/cookies", [{"User-agent", @userAgent}], hackney: [
            cookie: "cookie1=1 cookie2=2"]  ) do    

When I create a cookie it will store a domain like .httpbin.org but for dummy reason I need to set domain value like httpbin.org (without previous dot) .

I tried also with:

HTTPoison.get("httpbin.org/cookies", [{"User-agent", @userAgent}], hackney: [
                cookie: "cookie1=1 domain=httpbin.org cookie2=2"]  ) do 

But of course the syntax expects domain as a cookie name and httpbin.org as a cookie value.

Thank you!

1 Answers1

1

What's the reason you want to remove the dot in the beginning? It's optional and it should match the entire domain with/without the dot.

How do browser cookie domains work?

Also, I think the domain attribute would be for the Set-Cookie header returned from HTTP server rather than requesting from the client. The httpbin (https://httpbin.org/cookies/set) returns the Set-Cookie header, but it doesn't specify domain attribute (just Path=/). It would be taken as .httpbin.org by clients like browsers.

iex(25)> response = HTTPoison.get!("https://httpbin.org/cookies/set?k2=v2&k1=v1")
%HTTPoison.Response{body: "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2 Final//EN\">\n<title>Redirecting...</title>\n<h1>Redirecting...</h1>\n<p>You should be redirected automatically to target URL: <a href=\"/cookies\">/cookies</a>.  If not click the link.",
 headers: [{"Server", "nginx"}, {"Date", "Fri, 18 Dec 2015 23:49:46 GMT"},
  {"Content-Type", "text/html; charset=utf-8"}, {"Content-Length", "223"},
  {"Connection", "keep-alive"}, {"Location", "/cookies"},
  {"Set-Cookie", "k2=v2; Path=/"}, {"Set-Cookie", "k1=v1; Path=/"},
  {"Access-Control-Allow-Origin", "*"},
  {"Access-Control-Allow-Credentials", "true"}], status_code: 302}
iex(26)> :hackney.cookies(response.headers)
[{"k1", [{"k1", "v1"}, {"Path", "/"}]}, {"k2", [{"k2", "v2"}, {"Path", "/"}]}]

Sorry if I'm missing the point.

Community
  • 1
  • 1
parroty
  • 1,385
  • 9
  • 12