Issue #3916 - Fix whitespace between boundary and part headers

Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
This commit is contained in:
Joakim Erdfelt 2020-07-30 09:13:01 -05:00
parent f37f82828f
commit 36b42ca65d
No known key found for this signature in database
GPG Key ID: 2D0E1FB8FE4B68B4
1 changed files with 23 additions and 21 deletions

View File

@ -29,8 +29,8 @@ import java.nio.charset.StandardCharsets;
public class MultiPartOutputStream extends FilterOutputStream
{
private static final byte[] __CRLF = {'\r', '\n'};
private static final byte[] __DASHDASH = {'-', '-'};
private static final byte[] CRLF = {'\r', '\n'};
private static final byte[] DASHDASH = {'-', '-'};
public static final String MULTIPART_MIXED = "multipart/mixed";
public static final String MULTIPART_X_MIXED_REPLACE = "multipart/x-mixed-replace";
@ -71,11 +71,11 @@ public class MultiPartOutputStream extends FilterOutputStream
try
{
if (inPart)
out.write(__CRLF);
out.write(__DASHDASH);
out.write(CRLF);
out.write(DASHDASH);
out.write(boundaryBytes);
out.write(__DASHDASH);
out.write(__CRLF);
out.write(DASHDASH);
out.write(CRLF);
inPart = false;
}
finally
@ -104,15 +104,19 @@ public class MultiPartOutputStream extends FilterOutputStream
throws IOException
{
if (inPart)
out.write(__CRLF);
{
out.write(CRLF);
}
inPart = true;
out.write(__DASHDASH);
out.write(DASHDASH);
out.write(boundaryBytes);
out.write(__CRLF);
out.write(CRLF);
if (contentType != null)
{
out.write(("Content-Type: " + contentType).getBytes(StandardCharsets.ISO_8859_1));
out.write(__CRLF);
out.write(__CRLF);
out.write(CRLF);
}
out.write(CRLF);
}
/**
@ -126,20 +130,22 @@ public class MultiPartOutputStream extends FilterOutputStream
throws IOException
{
if (inPart)
out.write(__CRLF);
out.write(CRLF);
inPart = true;
out.write(__DASHDASH);
out.write(DASHDASH);
out.write(boundaryBytes);
out.write(__CRLF);
out.write(CRLF);
if (contentType != null)
{
out.write(("Content-Type: " + contentType).getBytes(StandardCharsets.ISO_8859_1));
out.write(__CRLF);
out.write(CRLF);
}
for (int i = 0; headers != null && i < headers.length; i++)
{
out.write(headers[i].getBytes(StandardCharsets.ISO_8859_1));
out.write(__CRLF);
out.write(CRLF);
}
out.write(__CRLF);
out.write(CRLF);
}
@Override
@ -148,7 +154,3 @@ public class MultiPartOutputStream extends FilterOutputStream
out.write(b, off, len);
}
}