Non sono così bravo in Java + Spring, ma mi piacerebbe aggiungere l'intestazione Cache-Control
al mio ResponseEntity
.Java + Spring Boot: Sto cercando di aggiungere l'intestazione di CacheControl a 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);
}
}
ho aggiunto due righe di codice per HttpHeaders
e ora ho due Cache-Control
intestazioni nella mia risposta:
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
Che cosa ho fatto di sbagliato? Qualcuno potrebbe darmi una mano.
Si sta utilizzando Sicurezza di primavera? –
Sì, la mia app ha l'autenticazione di base per raggiungere l'API REST. – user3742622