Repository: netty/netty (Java)

Issue:
HttpPostRequestEncoder will overwrite the original filename when switching to mixed mode
### Expected behavior
The `HttpPostRequestEncoder` preserves the original filename of file uploads sharing the same name encoded in mixed mode. 

### Actual behavior
The `HttpPostRequestEncoder` overwrites the original filename of file uploads sharing the same name encoded in mixed mode when it rewrites the multipart body header of the previous file.

### Steps to reproduce
Use an `HttpPostRequestEncoder` with multipart and the default mode and add several body file upload using the same name and different filenames. The test suite contains already such test but the test is wrong and will not check correctly that the original filename is preserved.

### Minimal yet complete reproducer code (or URL to code)
Update `HttpPostRequestEncoderTest#testMultiFileUploadInMixedMode` and change the first occurence of _filename=\"file-02.txt\""_ by _filename=\"file-01.txt\""_

### Netty version
All ?

### JVM version (e.g. `java -version`)
N/A

### OS version (e.g. `uname -a`)
N/A



Hints:

Patch:
diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/multipart/HttpPostRequestEncoder.java b/codec-http/src/main/java/io/netty/handler/codec/http/multipart/HttpPostRequestEncoder.java
--- a/codec-http/src/main/java/io/netty/handler/codec/http/multipart/HttpPostRequestEncoder.java
+++ b/codec-http/src/main/java/io/netty/handler/codec/http/multipart/HttpPostRequestEncoder.java
@@ -638,7 +638,7 @@ public void addBodyHttpData(InterfaceHttpData data) throws ErrorDataEncoderExcep
                         replacement.append("; ")
                                    .append(HttpHeaderValues.FILENAME)
                                    .append("=\"")
-                                   .append(fileUpload.getFilename())
+                                   .append(currentFileUpload.getFilename())
                                    .append('"');
                     }
 


Test patch:
diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/multipart/HttpPostRequestEncoderTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/multipart/HttpPostRequestEncoderTest.java
--- a/codec-http/src/test/java/io/netty/handler/codec/http/multipart/HttpPostRequestEncoderTest.java
+++ b/codec-http/src/test/java/io/netty/handler/codec/http/multipart/HttpPostRequestEncoderTest.java
@@ -139,9 +139,11 @@ public void testMultiFileUploadInMixedMode() throws Exception {
         HttpPostRequestEncoder encoder = new HttpPostRequestEncoder(request, true);
         File file1 = new File(getClass().getResource("/file-01.txt").toURI());
         File file2 = new File(getClass().getResource("/file-02.txt").toURI());
+        File file3 = new File(getClass().getResource("/file-03.txt").toURI());
         encoder.addBodyAttribute("foo", "bar");
         encoder.addBodyFileUpload("quux", file1, "text/plain", false);
         encoder.addBodyFileUpload("quux", file2, "text/plain", false);
+        encoder.addBodyFileUpload("quux", file3, "text/plain", false);
 
         // We have to query the value of these two fields before finalizing
         // the request, which unsets one of them.
@@ -160,7 +162,7 @@ public void testMultiFileUploadInMixedMode() throws Exception {
                 CONTENT_TYPE + ": multipart/mixed; boundary=" + multipartMixedBoundary + "\r\n" +
                 "\r\n" +
                 "--" + multipartMixedBoundary + "\r\n" +
-                CONTENT_DISPOSITION + ": attachment; filename=\"file-02.txt\"" + "\r\n" +
+                CONTENT_DISPOSITION + ": attachment; filename=\"file-01.txt\"" + "\r\n" +
                 CONTENT_LENGTH + ": " + file1.length() + "\r\n" +
                 CONTENT_TYPE + ": text/plain" + "\r\n" +
                 CONTENT_TRANSFER_ENCODING + ": binary" + "\r\n" +
@@ -175,6 +177,14 @@ public void testMultiFileUploadInMixedMode() throws Exception {
                 "\r\n" +
                 "File 02" + StringUtil.NEWLINE +
                 "\r\n" +
+                "--" + multipartMixedBoundary + "\r\n" +
+                CONTENT_DISPOSITION + ": attachment; filename=\"file-03.txt\"" + "\r\n" +
+                CONTENT_LENGTH + ": " + file3.length() + "\r\n" +
+                CONTENT_TYPE + ": text/plain" + "\r\n" +
+                CONTENT_TRANSFER_ENCODING + ": binary" + "\r\n" +
+                "\r\n" +
+                "File 03" + StringUtil.NEWLINE +
+                "\r\n" +
                 "--" + multipartMixedBoundary + "--" + "\r\n" +
                 "--" + multipartDataBoundary + "--" + "\r\n";
 
diff --git a/codec-http/src/test/resources/file-03.txt b/codec-http/src/test/resources/file-03.txt
new file mode 100644
--- /dev/null
+++ b/codec-http/src/test/resources/file-03.txt
@@ -0,0 +1 @@
+File 03