58 Star 432 Fork 114

smartboot / smart-http

 / 详情

[BUG] StaticResourceHandle处理的返回结果缺少content-length头信息

已完成
创建于  
2019-12-11 15:54
    @Override
    public void doHandle(HttpRequest request, HttpResponse response) throws IOException {
        ...
        ...
        ...
       response.setHeader(HttpHeaderConstant.Names.LAST_MODIFIED, sdf.get().format(lastModifyDate));
        
        //************ start:此处为我这边修改的内容 *****************
        response.setHeader(HttpHeaderConstant.Names.CONTENT_LENGTH, file.length()+"");
        //************ end:此处为我这边修改的内容 *****************

        String contentType = Mimetypes.getInstance().getMimetype(file);
        response.setHeader(HttpHeaderConstant.Names.CONTENT_TYPE, contentType + "; charset=utf-8");
        //HEAD不输出内容
        if (HttpMethodEnum.HEAD.getMethod().equals(method)) {
            return;
        }
        ...
        ...
        ...
    }

对于兼容性不好的浏览器,如果不返回长度会导致在下载大文件时失败或者不显示下载进度

        response.setHeader(HttpHeaderConstant.Names.CONTENT_LENGTH, file.length()+"");

评论 (1)

yn1994 创建了任务
yn1994 修改了描述
yn1994 修改了描述
三刀 负责人设置为zhengran
三刀 添加了
 
bug
标签
三刀 移除了
 
bug
标签
三刀 添加了
 
enhancement
标签
三刀 任务状态待办的 修改为进行中
展开全部操作日志

感谢你的建议。
在下个版本中会按照你的建议做调整。而对于html文件会依旧默认用 Transfer-Encoding: chunked,这样可以让浏览器边加载边渲染。

if (!file.getName().endsWith("html") && !file.getName().endsWith("htm")) {
    response.setContentLength((int) file.length());
}
三刀 任务状态进行中 修改为已完成

登录 后才可以发表评论

状态
负责人
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
参与者(2)
351975 smartdms 1578921064 110600 lyon1994 1578917969
Java
1
https://gitee.com/smartboot/smart-http.git
git@gitee.com:smartboot/smart-http.git
smartboot
smart-http
smart-http

搜索帮助