-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -786,20 +786,24 @@ public String toString() | |
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; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
joakime
Author
Contributor
|
||
response.setContentLength(length); | ||
|
||
try (RangeWriter rangeWriter = HttpContentRangeWriter.newRangeWriter(content)) | ||
|
@joakime Perhaps move all these calculations to a static member on
MultiPartOutputStream
? That way the calculations will be nearer the code that writes the boundary and less likely to be forgotten if it is changed again?