I use varnish cache some file like *.doc *.png *.xls.
It work well while I get files from cache but *.xls.
My URI is like /attachment/show?fileId=ewer232ewe2121eeddsd
. When I request a .xls file from cache, it will return a file named show
whitout extension.
My server code is:
if (StringUtil.null2Trim(attachment.getExtension()).equals("doc")
|| StringUtil.null2Trim(attachment.getExtension()).equals("docx")
|| StringUtil.null2Trim(attachment.getExtension()).equals("xlsx")
|| StringUtil.null2Trim(attachment.getExtension()).equals("xls")) {
response.setHeader("Content-Disposition", "attachment; filename=\""
+ StringUtil.gbk2Iso(attachment.getName()) + "\"");
if (StringUtil.null2Trim(attachment.getExtension()).indexOf("doc") != -1) {
response.setContentType("application/msword");
}
if (StringUtil.null2Trim(attachment.getExtension()).indexOf("xls") != -1) {
response.setContentType("application/vnd.ms-excel");
}
} else {
if (StringUtil.null2Trim(attachment.getExtension()).equals("jpg")) {
response.setContentType("image/jpeg");
} else if (StringUtil.null2Trim(attachment.getExtension()).equals("png")) {
response.setContentType("image/x-png");
} else {
response.setContentType("image/" + attachment.getExtension());
}
}
My question is:Why can't I get the correct file full name like attachment.getName()+".xls"
, and how to solve it.
PS: Is there any way to set ContentType in varnish(vcl)?