I have a controller method (3.0) that is returning a byte array for the purposes of downloading a file attachment:
public @ResponseBody byte viewAttachment(....);
I have tried to setContentType and also setHeader but these are ignored/overwritten in the final written output.
The result of the AnnotationMethodHandlerAdapter is that the Content Type is set to one of the values passed in the Accept header in the request.
Results in the Content-Type being returned as text/html which confuses the browser to the content type. I.e it wont allow the browser to open a PDF file directly.
You might ask why I am not using a ResponseEntity<byte> - There is a reason for that: If I use the ResponseEntity I can not override the no-cache and no-store headers. These can only be modified on a per-application basis which is undesirable.