Cookies with "Domain=localhost" aren't getting stored in session file
If I use httpie to make a call that returns cookies to a localhost address, such as:
http --session=./session.json POST http://localhost:9081/cookieTest
which sends back a header like this:
Set-Cookie: c1=test; Max-Age=298; Expires=Tue, 15-Aug-2017 19:17:58 GMT; Domain=localhost; Path=/; HttpOnly
but the session.json only includes the following:
{
"__meta__": {
"about": "HTTPie session file",
"help": "https://httpie.org/docs#sessions",
"httpie": "0.9.9"
},
"auth": {
"password": null,
"type": null,
"username": null
},
"cookies": {},
"headers": {
"Accept": "application/json, */*"
}
}
If I try this exact same process with the same code hosted at somedomain.com, it works perfectly. For example:
http --session=./session.json POST http://somedomain.com/cookieTest
which sends back a header like this:
Set-Cookie: c1=test; Max-Age=298; Expires=Tue, 15-Aug-2017 19:17:58 GMT; Domain=somedomain.com; Path=/; HttpOnly
and the session.json includes the following:
{
"__meta__": {
"about": "HTTPie session file",
"help": "https://httpie.org/docs#sessions",
"httpie": "0.9.9"
},
"auth": {
"password": null,
"type": null,
"username": null
},
"cookies": {
"c1": {
"expires": 1502824948,
"path": "/",
"secure": false,
"value": "test"
}
},
"headers": {
"Accept": "application/json, */*"
}
}
Is there any way to get it to work with localhost? Or is this a bug?
It seems to be a behavior inherited from requests. Alsocookie is being recognized and parsed if you don't setDomain, but not if domain is explicitly set to localhost.
Related #143
I just ran into the same problem (httpie not saving cookie in session when domain is set to localhost).
Is there a workaround within httpie?
The only way I can fix it is by not sending a domain in the cookie when serving from localhost:
$domain = (getenv('HTTP_HOST') == 'localhost' ? null : getenv('HTTP_HOST'));