【发布时间】:2016-11-03 01:23:25
【问题描述】:
我不太擅长 Java + Spring,但我想将 Cache-Control 标头添加到我的 ResponseEntity 中。
@RequestMapping(value = "/data/{id}", method = GET")
public ResponseEntity<String> getData(@PathVariable("id") String id) {
try {
...
HttpHeaders headers = new HttpHeaders();
headers.setCacheControl("max-age=600");
return new ResponseEntity<String>(body, headers, HttpStatus.OK);
}
}
我为HttpHeaders 添加了两行代码,现在我的响应中有两个Cache-Control 标头:
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
X-Frame-Options: DENY
Strict-Transport-Security: max-age=31536000 ; includeSubDomains
Cache-Control: max-age=600
Content-Type: application/json;charset=UTF-8
Content-Length: 18223
Date: Wed, 29 Jun 2016 21:56:57 GMT
我做错了什么?
【问题讨论】:
-
你在使用 Spring Security 吗?
-
是的,我的应用具有访问 REST API 的基本身份验证。
标签: java spring spring-mvc spring-security spring-boot