Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cookie domain and path with jax-rs

I'm using jax-rs and trying to add a cookie to my response. The problem is that when adding a cookie the following way:

new NewCookie("cookie-name", "cookie-value");

the cookie is being attached only to the requests of the same path. For example, if I add the cookie in the request "/myapp/users/login", I don't see that cookie when calling other requests. I think the explanation to this is that, for some reason, the path of the cookie is "/myapp/users" so when calling "myapp/someotherpath" the cookie is not being attached.

I tried using another constructor of NewCookie where I can set domain and path but couldn't make it work, can some one give me an example of setting domain and path that will attach the cookie to all requests? isn't this supposed to be the default behavior anyway?

like image 693
julius_am Avatar asked Aug 10 '14 05:08

julius_am


1 Answers

To attach the cookie to all requests the domain and path should be: domain = ""; path = "/"

So the cookie creation will look as follows:

NewCookie("cookie-name", "cookie-value", "/", "", "comment", 100, false);
like image 114
julius_am Avatar answered Oct 12 '22 17:10

julius_am