Jelajahi Sumber

修改 getObject 返回的 Content-Length

reghao 2 tahun lalu
induk
melakukan
ca4a441034

+ 3 - 3
dfs-store/src/main/java/cn/reghao/dfs/store/service/GetObjectService.java

@@ -76,7 +76,7 @@ public class GetObjectService {
             String[] arr = rangeStr.replace("bytes=", "").split("-");
             long start = Long.parseLong(arr[0]);
             if (arr.length == 1) {
-                writeContentRange(objectMeta, start, objectMeta.getSize());
+                writeContentRange(objectMeta, start, len);
             } else {
                 ContentRange contentRange = parseContentRange(range, len);
                 writeContentRange(objectMeta, contentRange.getStart(), contentRange.getEnd());
@@ -126,9 +126,9 @@ public class GetObjectService {
         HttpServletResponse response = ServletUtil.getResponse();
         response.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT);
         response.setContentType(objectMeta.getContentType());
-        response.setHeader("Content-Length", ""+contentLength);
+        response.setHeader("Content-Length", ""+(end-start+1));
         response.setHeader("Accept-Ranges", "bytes");
-        response.setHeader("Content-Range", "bytes "+start+"-"+(end-1)+"/"+contentLength);
+        response.setHeader("Content-Range", "bytes "+start+"-"+end+"/"+contentLength);
 
         String absolutePath = objectMeta.getAbsolutePath();
         OutputStream outputStream = response.getOutputStream();