|
20 | 20 | import java.util.HashSet;
|
21 | 21 | import java.util.List;
|
22 | 22 | import java.util.Map;
|
| 23 | +import java.util.OptionalLong; |
23 | 24 | import java.util.Set;
|
24 | 25 | import java.util.SortedMap;
|
25 | 26 | import java.util.SortedSet;
|
|
50 | 51 | import jakarta.json.JsonReader;
|
51 | 52 | import jakarta.json.JsonValue;
|
52 | 53 | import jakarta.json.stream.JsonGenerator;
|
| 54 | +import static jakarta.ws.rs.core.HttpHeaders.CONTENT_LENGTH; |
53 | 55 | import jakarta.ws.rs.core.Response;
|
54 | 56 | import jakarta.ws.rs.core.StreamingOutput;
|
55 | 57 |
|
@@ -859,6 +861,7 @@ public Response getData(String sessionId, String investigationIds, String datase
|
859 | 861 | // Do it
|
860 | 862 | Map<Long, DsInfo> dsInfos = dataSelection.getDsInfo();
|
861 | 863 | Set<DfInfoImpl> dfInfos = dataSelection.getDfInfo();
|
| 864 | + var length = zip ? OptionalLong.empty() : dataSelection.getFileLength(); |
862 | 865 |
|
863 | 866 | Lock lock = null;
|
864 | 867 | try {
|
@@ -909,11 +912,14 @@ public Response getData(String sessionId, String investigationIds, String datase
|
909 | 912 | }
|
910 | 913 | }
|
911 | 914 |
|
912 |
| - return Response.status(offset == 0 ? HttpURLConnection.HTTP_OK : HttpURLConnection.HTTP_PARTIAL) |
| 915 | + var response = Response.status(offset == 0 ? HttpURLConnection.HTTP_OK : HttpURLConnection.HTTP_PARTIAL) |
913 | 916 | .entity(new SO(dataSelection.getDsInfo(), dataSelection.getDfInfo(), offset, finalZip, compress, lock,
|
914 | 917 | transferId, ip, start))
|
915 |
| - .header("Content-Disposition", "attachment; filename=\"" + name + "\"").header("Accept-Ranges", "bytes") |
916 |
| - .build(); |
| 918 | + .header("Content-Disposition", "attachment; filename=\"" + name + "\"").header("Accept-Ranges", "bytes"); |
| 919 | + length.stream() |
| 920 | + .map(l -> Math.max(0L, l - offset)) |
| 921 | + .forEach(l -> response.header(CONTENT_LENGTH, l)); |
| 922 | + return response.build(); |
917 | 923 | } catch (AlreadyLockedException e) {
|
918 | 924 | logger.debug("Could not acquire lock, getData failed");
|
919 | 925 | throw new DataNotOnlineException("Data is busy");
|
|
0 commit comments