Skip to content

Commit 17265d0

Browse files
committed
Fix - handle reordering of fragments in multipart reply #319
In case when reordering detected - try to search in all requested fragments for provided data range. Will not work if server creates more fragments than requested. Coalesing should be OK. Special situation of EOS server
1 parent 5b4f945 commit 17265d0

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

modules/io.mjs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2896,7 +2896,7 @@ class TFile {
28962896
// multipart messages requires special handling
28972897

28982898
const indx = hdr.indexOf('boundary=');
2899-
let boundary = '', n = first, o = 0;
2899+
let boundary = '', n = first, o = 0, normal_order = true;
29002900
if (indx > 0) {
29012901
boundary = hdr.slice(indx + 9);
29022902
if ((boundary[0] === '"') && (boundary[boundary.length - 1] === '"'))
@@ -2950,12 +2950,34 @@ class TFile {
29502950
blobs.push(new DataView(res, o, place[n + 1]));
29512951
o += place[n + 1];
29522952
n += 2;
2953-
} else {
2953+
} else if (normal_order) {
2954+
const n0 = n;
29542955
while ((n < last) && (place[n] >= segm_start) && (place[n] + place[n + 1] - 1 <= segm_last)) {
29552956
blobs.push(new DataView(res, o + place[n] - segm_start, place[n + 1]));
29562957
n += 2;
29572958
}
29582959

2960+
if (n > n0)
2961+
o += (segm_last - segm_start + 1);
2962+
else
2963+
normal_order = false;
2964+
}
2965+
2966+
if (!normal_order) {
2967+
// special situation when server reorder segments in the reply
2968+
let isany = false;
2969+
for (let n1 = n; n1 < last; n1 += 2) {
2970+
if ((place[n1] >= segm_start) && (place[n1] + place[n1 + 1] - 1 <= segm_last)) {
2971+
blobs[n1/2] = new DataView(res, o + place[n1] - segm_start, place[n1 + 1]);
2972+
isany = true;
2973+
}
2974+
}
2975+
if (!isany)
2976+
return rejectFunc(Error(`Provided fragment ${segm_start} - ${segm_last} out of requested multi-range request`));
2977+
2978+
while (blobs[n/2])
2979+
n += 2;
2980+
29592981
o += (segm_last - segm_start + 1);
29602982
}
29612983
}

0 commit comments

Comments
 (0)