我有以下设置:
- 所有请求都是https(我将在下面的描述中省略这一点( 3 个 docker 服务器:本地主机:8090、本地主机:
- 8091、本地主机:8092
- 在主机中(在我的Windows机器上(,我有3个域:loc.localdomain,loc2.localdomain和loc3.localdomain都指向我的IP地址 所以我将在我的应用程序中使用 localhost:8090 -> loc.localdomain、localhost:8091 -> loc2.localdomain
- 和 localhost:8092 -> loc3.localdomain
现在我在loc
上有一个应用程序,可以为loc3
子域设置一些cookie。我看到 cookie 在 chrome 网络响应中设置(或假设设置(。
Set-Cookie: MY_COOKIE=YUMM; domain=loc3.localdomain;
expires=Fri, 21-Jun-2019 10:48:58 GMT; path=/coolApp/bro
然后在应用程序中loc
我有一个按钮,可以将用户发送到另一个应用程序中loc2
将用户重定向到loc3
在loc3.localdomain:8092/coolApp/bro/something/more
.所以在这个时间点,我应该在应用程序请求中看到 cookieloc3
,但我没有。
饼干设置:
FacesContext facesContext = FacesContext.getCurrentInstance();
//facesContext.getExternalContext().addResponseCookie("TEST", "TEST", properties); tried this too
//then in properties will be the maxAge, path and domain set
Cookie cookie = (Cookie) facesContext.getExternalContext().getRequestCookieMap().get("MY_COOKIE");
if(cookie == null){
cookie = new Cookie("MY_COOKIE", "YUMMM");
}
cookie.setMaxAge(31536000);
cookie.setPath("/coolApp/bro");
cookie.setDomain("loc3.localdomain"); // I've tried ".localdomain" too
HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();
response.addCookie(cookie);
知道这个设置有什么问题吗?
基于此(https://curl.haxx.se/rfc/cookie_spec.html(,域应至少包含2个点,因此答案是使用本地主机的其他别名来模拟我的子域。像这样:*.example.com
更改域后,所有工作都按预期工作。