2012-10-22 5 views
0

나는 바니시 캐시를 * .doc * .png * .xls와 같은 일부 파일을 사용합니다.바니시 캐시에서 올바른 .xls 파일을 얻는 방법은 무엇입니까?

캐시에서 파일을 가져 오는 동안 * .xls 파일은 정상적으로 작동합니다.

내 URI는 /attachment/show?fileId=ewer232ewe2121eeddsd입니다. 캐시에서 .xls 파일을 요청하면 show whitout 확장명의 파일이 반환됩니다.

내 서버 코드는 다음과 같습니다

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()); 
       } 
      } 

내 질문은 : 나는 attachment.getName()+".xls"처럼 올바른 파일 이름을 얻을 수없고, 왜 그 해결 방법.

추 신 : 니스 (vcl)에서 ContentType을 설정하는 방법이 있습니까?

+1

이 메시지는 Varnish가 아니라 백엔드 서버 애플릿의 문제와 같습니다. 서버가 반환 한 정확한 헤더는 무엇입니까? – Ketola

+0

@Ketola 예, 서버가 잘못된 헤더를 설정했습니다. 이제 제대로 작동합니다. – lichengwu

답변

1

마지막 질문에 대답하겠습니다. Varnish의 모든 HTTP 응답 헤더를 대체 할 수 있습니다.

사용은 다음과 VCL은 니펫을 : 일반적으로

sub vcl_fetch { 
    if (req.url ~ ".xls$") { 
     set beresp.http.content-type = "application/vnd.ms-excel"; 
    } 
} 

추가하고 수행하여 뜻에서 헤더를 제거 할 수 있습니다 "beresp.http.XXX = YYY를 설정;" 또는 "unres beresp.http.XXX;" vcl_fetch에서.

MIME 봉투 (헤더 example here)를 추가하면 주요 질문에 답해 드리겠습니다.

관련 문제