1

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?

4
  • Check stackoverflow.com/a/3097052/9068895 Commented Feb 15, 2023 at 23:12
  • @Alex my question is why am getting two cache-control headers, even if i added only one Commented Feb 16, 2023 at 9: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 Commented Feb 16, 2023 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. Commented Aug 24, 2023 at 11:24

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.