hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r996639 - in /httpcomponents/httpclient/trunk: RELEASE_NOTES.txt httpmime/src/main/java/org/apache/http/entity/mime/HttpMultipart.java httpmime/src/test/java/org/apache/http/entity/mime/TestMultipartForm.java
Date Mon, 13 Sep 2010 18:55:57 GMT
Author: olegk
Date: Mon Sep 13 18:55:56 2010
New Revision: 996639

URL: http://svn.apache.org/viewvc?rev=996639&view=rev
Log:
HTTPCLIENT-960: HttpMultipart doesn't generate Content-Type header for binary parts in BROWSER_COMPATIBLE
mode

Modified:
    httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
    httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/HttpMultipart.java
    httpcomponents/httpclient/trunk/httpmime/src/test/java/org/apache/http/entity/mime/TestMultipartForm.java

Modified: httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/RELEASE_NOTES.txt?rev=996639&r1=996638&r2=996639&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpclient/trunk/RELEASE_NOTES.txt Mon Sep 13 18:55:56 2010
@@ -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>

Modified: httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/HttpMultipart.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/HttpMultipart.java?rev=996639&r1=996638&r2=996639&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/HttpMultipart.java
(original)
+++ httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/HttpMultipart.java
Mon Sep 13 18:55:56 2010
@@ -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);

Modified: httpcomponents/httpclient/trunk/httpmime/src/test/java/org/apache/http/entity/mime/TestMultipartForm.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpmime/src/test/java/org/apache/http/entity/mime/TestMultipartForm.java?rev=996639&r1=996638&r2=996639&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpmime/src/test/java/org/apache/http/entity/mime/TestMultipartForm.java
(original)
+++ httpcomponents/httpclient/trunk/httpmime/src/test/java/org/apache/http/entity/mime/TestMultipartForm.java
Mon Sep 13 18:55:56 2010
@@ -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";



Mime
View raw message