0

I am not so good in Java + Spring, but I'd like to add Cache-Control header to my 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, public");

            return new ResponseEntity<String>(body, headers, HttpStatus.OK);
        }
}

I added two lines of code for HttpHeaders and now I get two Cache-Control headers in my response:

one with public and another with private. why?

Alex
  • 4,987
  • 1
  • 8
  • 26
user2390827
  • 115
  • 2
  • 7
  • 15
  • Check https://stackoverflow.com/a/3097052/9068895 – Alex Feb 15 '23 at 23:12
  • @Alex my question is why am getting two cache-control headers, even if i added only one – user2390827 Feb 16 '23 at 09:13
  • Doesn't look like spring logic until you have some special global handlers. Checked in our environment and single header is returned in curl, Safari, Chrome – Alex Feb 16 '23 at 16:24
  • Does this appear in your local testing environment or on a "real" server? An intermediate proxy server or container configuration etc. could add a header to the request without checking that you already have one set for Cache-Control. – cyberbrain Aug 24 '23 at 11:24

0 Answers0