Http Cookie 探索

Meta 信息不见了

参考:
http://blog.csdn.net/lijing198997/article/details/9378047
http://*.com/questions/1062963/how-do-browser-cookie-domains-work
Domain and Path
作用:定义Cookie的生效作用域,只有当域名和路径同时满足的时候,浏览器才会将Cookie发送给Server。如果没有设置Domain和Path的话,他们会被默认为当前请求页面对应值。

Cookie with Domain=.example.com will be available for www.example.com
Cookie with Domain=.example.com will be available for example.com
Cookie with Domain=example.com will be converted to .example.com and thus will also be available for www.example.com
Cookie with Domain=example.com will not be available for anotherexample.com
跨域的请求是无法设置cookie的。 ()

Example:

Tomcat Java Web App通过服务端来设置浏览器cookie

服务端在请求的返回中向客户端的浏览器添加cookie。

示例的服务的context path 为/bee

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
@RequestMapping(value = "/cookietest", headers = "Accept=image/**", method = RequestMethod.GET)
public ResponseEntity<?> cookieTest(final HttpServletRequest request,HttpServletResponse response) {
Cookie cookie1 = new Cookie("cookie-1",UUID.randomUUID().toString());
cookie1.setDomain("diaoyouyun.com");
cookie1.setPath("/");
response.addCookie(cookie1);

Cookie cookie2 = new Cookie("cookie2","Cookie2");
cookie2.setDomain("www.diaoyouyun.com");
cookie2.setPath("/bee/collect");
response.addCookie(cookie2);

Cookie cookie3 = new Cookie("cookie3","cookie3");
cookie3.setDomain("www.example.com");
response.addCookie(cookie3);

Cookie cookie4 = new Cookie("cookie4","cookie4");
response.addCookie(cookie4);
return ok();
}

测试一

请求 http://diaoyouyun.com/bee/cookietest 如下:
Http Cookie 探索

那些cookie会被接受呢?访问http://diaoyouyun.com/bee 从下图可以看出
Http Cookie 探索大专栏

上一篇:Angular 项目中的可摇树依赖 - Tree-shakable dependencies


下一篇:Thread Process 线程 进程