HTTPCLIENT-960: HttpMultipart doesn't generate Content-Type header for binary parts in BROWSER_COMPATIBLE mode
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@996639 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
aeffde46e6
commit
05deb28605
|
@ -1,6 +1,10 @@
|
|||
Changes since 4.1 ALPHA2
|
||||
-------------------
|
||||
|
||||
* [HTTPCLIENT-960] HttpMultipart doesn't generate Content-Type header for binary parts in
|
||||
BROWSER_COMPATIBLE mode.
|
||||
Contributed by Oleg Kalnichevski <olegk at apache.org>
|
||||
|
||||
* [HTTPCLIENT-989] DefaultHttpRequestRetryHandler no longer retries non-idempotent http methods
|
||||
if NoHttpResponseException is thrown.
|
||||
Contributed by Oleg Kalnichevski <olegk at apache.org>
|
||||
|
|
|
@ -73,6 +73,22 @@ public class HttpMultipart {
|
|||
writeBytes(b, out);
|
||||
}
|
||||
|
||||
private static void writeField(
|
||||
final MinimalField field, final OutputStream out) throws IOException {
|
||||
writeBytes(field.getName(), out);
|
||||
writeBytes(FIELD_SEP, out);
|
||||
writeBytes(field.getBody(), out);
|
||||
writeBytes(CR_LF, out);
|
||||
}
|
||||
|
||||
private static void writeField(
|
||||
final MinimalField field, final Charset charset, final OutputStream out) throws IOException {
|
||||
writeBytes(field.getName(), charset, out);
|
||||
writeBytes(FIELD_SEP, out);
|
||||
writeBytes(field.getBody(), charset, out);
|
||||
writeBytes(CR_LF, out);
|
||||
}
|
||||
|
||||
private static final ByteArrayBuffer FIELD_SEP = encode(MIME.DEFAULT_CHARSET, ": ");
|
||||
private static final ByteArrayBuffer CR_LF = encode(MIME.DEFAULT_CHARSET, "\r\n");
|
||||
private static final ByteArrayBuffer TWO_DASHES = encode(MIME.DEFAULT_CHARSET, "--");
|
||||
|
@ -151,20 +167,19 @@ public class HttpMultipart {
|
|||
switch (mode) {
|
||||
case STRICT:
|
||||
for (MinimalField field: header) {
|
||||
writeBytes(field.getName(), out);
|
||||
writeBytes(FIELD_SEP, out);
|
||||
writeBytes(field.getBody(), out);
|
||||
writeBytes(CR_LF, out);
|
||||
writeField(field, out);
|
||||
}
|
||||
break;
|
||||
case BROWSER_COMPATIBLE:
|
||||
// Only write Content-Disposition
|
||||
// Use content charset
|
||||
MinimalField cd = part.getHeader().getField(MIME.CONTENT_DISPOSITION);
|
||||
writeBytes(cd.getName(), this.charset, out);
|
||||
writeBytes(FIELD_SEP, out);
|
||||
writeBytes(cd.getBody(), this.charset, out);
|
||||
writeBytes(CR_LF, out);
|
||||
writeField(cd, this.charset, out);
|
||||
String filename = part.getBody().getFilename();
|
||||
if (filename != null) {
|
||||
MinimalField ct = part.getHeader().getField(MIME.CONTENT_TYPE);
|
||||
writeField(ct, this.charset, out);
|
||||
}
|
||||
break;
|
||||
}
|
||||
writeBytes(CR_LF, out);
|
||||
|
|
|
@ -258,11 +258,13 @@ public class TestMultipartForm {
|
|||
"--foo\r\n" +
|
||||
"Content-Disposition: form-data; name=\"field1\"; " +
|
||||
"filename=\"" + s1 + ".tmp\"\r\n" +
|
||||
"Content-Type: application/octet-stream\r\n" +
|
||||
"\r\n" +
|
||||
"some random whatever\r\n" +
|
||||
"--foo\r\n" +
|
||||
"Content-Disposition: form-data; name=\"field2\"; " +
|
||||
"filename=\"" + s2 + ".tmp\"\r\n" +
|
||||
"Content-Type: application/octet-stream\r\n" +
|
||||
"\r\n" +
|
||||
"some random whatever\r\n" +
|
||||
"--foo--\r\n";
|
||||
|
|
Loading…
Reference in New Issue