I am using wildfly-9 with java-8 on windows OS.
I have implemented changes in spring-boot to support Range with gzip compression/encoding.
consider below pseudo code code to get GZIPOutputStream
from javax.servlet.ServletResponse.getOutputStream()
OutputStream gzos;
if(fileName.indexOf(".") > 0){
fileExtension = fileName.substring(fileName.lastIndexOf("."));
response.setContentType(DownloadUtil.getContentType(fileExtension));
}
String disposition = getContentDispositionParameter(request, fileName);
response.setHeader("Content-Disposition", disposition);
if(fileExtension.equalsIgnoreCase(".zip") || DownloadUtil.isGZipSuppored(request)==false || fileExtension.equalsIgnoreCase(".file")){
response.setHeader("Content-Length", String.valueOf(fileSize));
gzos = response.getOutputStream();
} else {
response.setHeader("Content-Encoding", "gzip");
gzos = new GZIPOutputStream(response.getOutputStream());
}
return new BufferedOutputStream(gzos);
Using this BufferedOutputStream object to send file's data with some other headers.
Facing issue in case of interruption while download file in chrome browser(i.e. service re-start while download file)
For initial download request
accept-encoding = gzip, deflate, br
is passed while after interrupted download, when user resume download chrome browser is sending
accept-encoding = identity
Due to this I am not able to identify whether browser is supporting gzip encoding or not & So, I need to send non-gzip response.
Note: In firefox I am getting accept-encoding = gzip
in Range request.
Initial request request/response header
============== Request headers===============
host=localhost:9097
connection=keep-alive
sec-ch-ua="Google Chrome";v="107", "Chromium";v="107", "Not=A?Brand";v="24"
sec-ch-ua-mobile=?0
sec-ch-ua-platform="Windows"
upgrade-insecure-requests=1
user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36
accept=text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
sec-fetch-site=none
sec-fetch-mode=navigate
sec-fetch-user=?1
sec-fetch-dest=document
accept-encoding=gzip, deflate, br
accept-language=en-US,en;q=0.9
============== Response headers===============
Content-Disposition=attachment;filename="24371676.txt"
Accept-Ranges=bytes
ETag=24371676.txt_43371681_1667802564570
Last-Modified=Mon, 07 Nov 2022 06:29:24 GMT
Expires=Tue, 22 Nov 2022 12:16:13 GMT
Content-Encoding=gzip
Content-Range=bytes 0-43371680/43371681
Range request(resume after interrupted download) request/response header
============== Request headers===============
host=localhost:9097
connection=keep-alive
range=bytes=10373334-
if-range=24371676.txt_43371681_1667802564570
accept-encoding=identity
sec-fetch-site=none
sec-fetch-mode=navigate
sec-fetch-dest=empty
user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36
accept-language=en-US,en;q=0.9
============== Response headers===============
Content-Disposition=attachment;filename="24371676.txt"
Accept-Ranges=bytes
ETag=24371676.txt_43371681_1667802564570
Last-Modified=Mon, 07 Nov 2022 06:29:24 GMT
Expires=Tue, 22 Nov 2022 12:17:34 GMT
Content-Range=bytes 10373334-43371680/43371681
Is there any configuration or header needs to be added So, I can get request header accept-encoding=gzip, deflate, br
and I can supply gzip response in chrome.
Edit: I have also refer: Issue making range requests in some browsers and seems like there is specification is changed