I'm trying to serve gzipped log files using Spring Boot REST.
Files are already gzipped, I don't need to gzip them.
Browser should unzip them and show plain text.
Based on the info I googled, I need two things to make it work:
'Accept-Encoding': 'gzip''Content-Encoding': 'gzip'Request is OK:

Response is NOT - missing Content-Encoding header:

Here is my Java code:
@RequestMapping(value = "/download",
method = RequestMethod.GET)
public ResponseEntity<InputStreamResource> download(HttpServletRequest request, HttpServletResponse response) {
log.debug("REST request to get the filesystem resource");
// hardcoded for testing purpose
File f = new File("C:/file.log.gz");
InputStream inputStream = null;
InputStreamResource inputStreamResource = null;
HttpHeaders headers = null;
try {
inputStream = new FileInputStream(f);
inputStreamResource = new InputStreamResource(inputStream);
headers = new HttpHeaders();
headers.add("Cache-Control", "no-cache, no-store, must-revalidate");
headers.add("Pragma", "no-cache");
headers.add("Expires", "0");
headers.add("Content-Encoding", "gzip");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
return ResponseEntity
.ok()
.headers(headers)
.contentType(MediaType.parseMediaType("text/plain"))
.body(inputStreamResource);
}
Is Spring removing this specific header from response?
I just found out that it is actually working :). I was using BrowserSync before to test it out and it's not working with BrowserSync for some reason.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With