我有以下设置:
- 所有请求都是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
设置一些 cookieloc3
子域。我看到 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
at loc3.localdomain:8092/coolApp/bro/something/more
。所以此时我应该在应用程序请求中看到 cookieloc3
,但我没有。
Cookie 设置:
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 https://curl.haxx.se/rfc/cookie_spec.html)域应至少包含 2 个点,因此答案是使用 localhost 的其他别名来模拟我的子域。就像是:*.example.com
更改域名后,一切都按预期进行。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)