Issue #3916 - Improve multi range response Content-Length calc
Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
This commit is contained in:
parent
2206b3edae
commit
dcf867cd2b
|
@ -786,20 +786,24 @@ public class ResourceService
|
|||
int length = 0;
|
||||
String[] header = new String[ranges.size()];
|
||||
int i = 0;
|
||||
final int CRLF = "\r\n".length();
|
||||
final int DASHDASH = "--".length();
|
||||
final int BOUNDARY = multi.getBoundary().length();
|
||||
final int FIELD_SEP = ": ".length();
|
||||
for (InclusiveByteRange ibr : ranges)
|
||||
{
|
||||
header[i] = ibr.toHeaderRangeString(content_length);
|
||||
if (i > 0) // in-part
|
||||
length += 2;
|
||||
length += 2 + multi.getBoundary().length() + 2; // "--" boundary CR LF
|
||||
length += CRLF;
|
||||
length += DASHDASH + BOUNDARY + CRLF;
|
||||
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
|
||||
length += HttpHeader.CONTENT_TYPE.asString().length() + FIELD_SEP + mimetype.length() + CRLF;
|
||||
length += HttpHeader.CONTENT_RANGE.asString().length() + FIELD_SEP + header[i].length() + CRLF;
|
||||
length += CRLF;
|
||||
length += ibr.getSize();
|
||||
i++;
|
||||
}
|
||||
length += 2 + 2 + multi.getBoundary().length() + 2 + 2; // CR LF "--" boundary "--" CR LF
|
||||
length += CRLF + DASHDASH + BOUNDARY + DASHDASH + CRLF;
|
||||
response.setContentLength(length);
|
||||
|
||||
try (RangeWriter rangeWriter = HttpContentRangeWriter.newRangeWriter(content))
|
||||
|
|
Loading…
Reference in New Issue