Issue #3916 - Fixing broken Content-Length evaluation

Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
This commit is contained in:
Joakim Erdfelt 2020-08-08 07:18:02 -05:00
parent 1f14dfa427
commit 2206b3edae
No known key found for this signature in database
GPG Key ID: 2D0E1FB8FE4B68B4
1 changed files with 9 additions and 8 deletions

View File

@ -789,16 +789,17 @@ public class ResourceService
for (InclusiveByteRange ibr : ranges)
{
header[i] = ibr.toHeaderRangeString(content_length);
length +=
((i > 0) ? 2 : 0) +
2 + multi.getBoundary().length() + 2 +
(mimetype == null ? 0 : HttpHeader.CONTENT_TYPE.asString().length() + 2 + mimetype.length()) + 2 +
HttpHeader.CONTENT_RANGE.asString().length() + 2 + header[i].length() + 2 +
2 +
(ibr.getLast() - ibr.getFirst()) + 1;
if (i > 0) // in-part
length += 2;
length += 2 + multi.getBoundary().length() + 2; // "--" boundary CR LF
if (mimetype != null)
length += HttpHeader.CONTENT_TYPE.asString().length() + 2 + mimetype.length() + 2; // "Content-Type" ": " <len> CR LF
length += HttpHeader.CONTENT_RANGE.asString().length() + 2 + header[i].length() + 2; // "Content-Range" ": " <len> CR LF
length += 2; // CR LF
length += ((ibr.getLast() - ibr.getFirst()) + 1); // content size
i++;
}
length += 2 + 2 + multi.getBoundary().length() + 2 + 2;
length += 2 + 2 + multi.getBoundary().length() + 2 + 2; // CR LF "--" boundary "--" CR LF
response.setContentLength(length);
try (RangeWriter rangeWriter = HttpContentRangeWriter.newRangeWriter(content))