【发布时间】:2018-11-30 16:29:59
【问题描述】:
我有以下设置:
- 所有请求都是https(我将在下面的描述中省略它)
- 3个docker服务器:localhost:8090, localhost:8091, localhost: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.localdomain:8092/coolApp/bro/something/more 的loc3。因此,此时我应该在loc3 处看到应用请求中的 cookie,但我没有。
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);
知道这个设置有什么问题吗?
【问题讨论】: