You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by GitBox <gi...@apache.org> on 2021/11/09 02:50:23 UTC

[GitHub] [servicecomb-java-chassis] five111 commented on issue #2620: 使用官方文档的推荐方式写文件下载接口,客户端为go服务时会报错

five111 commented on issue #2620:
URL: https://github.com/apache/servicecomb-java-chassis/issues/2620#issuecomment-963765088


   这个问题目前已经分析清楚 在这里分享一下
   
   ## 接口为什么调不通
   上文已经说得很清楚了 go1.15之后版本处于安全考虑加强了对请求头的校验
   
   ##为什么请求头会多,来自哪里
   ### 首先 java-chassis在下载的方法确实会添加请求头
   org.apache.servicecomb.foundation.vertx.http.DownloadUtils 中会根据是否设置了请求长度来添加transfer-encoding
   ```
   public static void prepareDownloadHeader(HttpServletResponseEx responseEx, Part part, boolean needChunked) {
       if (responseEx.getHeader(HttpHeaders.CONTENT_LENGTH.toString()) == null && needChunked) {
         responseEx.setChunked(true);
       }
       if (responseEx.getHeader(HttpHeaders.CONTENT_TYPE.toString()) == null) {
         responseEx.setHeader(HttpHeaders.CONTENT_TYPE.toString(), part.getContentType());
       }
   
       if (responseEx.getHeader(javax.ws.rs.core.HttpHeaders.CONTENT_DISPOSITION) == null) {
         // to support chinese and space filename in firefox
         // must use "filename*", (https://tools.ietf.org/html/rtf6266)
         String encodedFileName = HttpUtils.uriEncodePath(part.getSubmittedFileName());
         responseEx.setHeader(javax.ws.rs.core.HttpHeaders.CONTENT_DISPOSITION,
             "attachment;filename=" + encodedFileName + ";filename*=utf-8''" + encodedFileName);
       }
     }
   ```
   ### 请求头变多的场景
    如果你使用java-chassis的方式是rest-over-vertx,那么当前场景不会有任何问题,但是 如果你使用的方式是rest-over-servlet模式, 这里大部分使用的web容器都是tomcat,那么tomcat有一段逻辑会在他的缓冲区无法缓冲所有的请求内容时,添加这个请求头,导致多个chunked
   
   ##解决办法
   目前没有太好的办法 
   出于进度压力和使用场景 我目前先对java-chassis做了部分侵入式修改 在使用方式为servlet时,不添加此请求头
   同时我在与tomcat社区的人联系,希望他们在添加请求头之前能够校验是否已经存在此请求头
   
   @liubao
   @wujimin 
   @fanjiwang1992 
   不知3位有何看法


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org