Backport the HttpPostRequestEncoder fixes by @igstan

This commit is contained in:
Trustin Lee 2014-01-19 22:21:24 +09:00
parent f3482670f9
commit 95bcbe5e08
3 changed files with 16 additions and 7 deletions

View File

@ -101,7 +101,7 @@ public class HttpPostRequestEncoder implements ChunkedInput<HttpContent> {
/** /**
* The final Multipart List of InterfaceHttpData including encoding * The final Multipart List of InterfaceHttpData including encoding
*/ */
private final List<InterfaceHttpData> multipartHttpDatas; final List<InterfaceHttpData> multipartHttpDatas;
/** /**
* Does this request is a Multipart request * Does this request is a Multipart request
@ -111,12 +111,12 @@ public class HttpPostRequestEncoder implements ChunkedInput<HttpContent> {
/** /**
* If multipart, this is the boundary for the flobal multipart * If multipart, this is the boundary for the flobal multipart
*/ */
private String multipartDataBoundary; String multipartDataBoundary;
/** /**
* If multipart, there could be internal multiparts (mixed) to the global multipart. Only one level is allowed. * If multipart, there could be internal multiparts (mixed) to the global multipart. Only one level is allowed.
*/ */
private String multipartMixedBoundary; String multipartMixedBoundary;
/** /**
* To check if the header has been finalized * To check if the header has been finalized
*/ */
@ -559,8 +559,12 @@ public class HttpPostRequestEncoder implements ChunkedInput<HttpContent> {
// remove past size // remove past size
globalBodySize -= pastAttribute.size(); globalBodySize -= pastAttribute.size();
StringBuilder replacement = new StringBuilder( StringBuilder replacement = new StringBuilder(
139 + multipartMixedBoundary.length() * 2 + 139 + multipartDataBoundary.length() + multipartMixedBoundary.length() * 2 +
fileUpload.getName().length() + fileUpload.getFilename().length()); fileUpload.getFilename().length() + fileUpload.getName().length());
replacement.append("--");
replacement.append(multipartDataBoundary);
replacement.append("\r\n");
replacement.append(HttpPostBodyUtil.CONTENT_DISPOSITION); replacement.append(HttpPostBodyUtil.CONTENT_DISPOSITION);
replacement.append(": "); replacement.append(": ");
@ -583,9 +587,10 @@ public class HttpPostRequestEncoder implements ChunkedInput<HttpContent> {
replacement.append("--"); replacement.append("--");
replacement.append(multipartMixedBoundary); replacement.append(multipartMixedBoundary);
replacement.append("\r\n"); replacement.append("\r\n");
replacement.append(HttpPostBodyUtil.CONTENT_DISPOSITION); replacement.append(HttpPostBodyUtil.CONTENT_DISPOSITION);
replacement.append(": "); replacement.append(": ");
replacement.append(HttpPostBodyUtil.FILE); replacement.append(HttpPostBodyUtil.ATTACHMENT);
replacement.append("; "); replacement.append("; ");
replacement.append(HttpPostBodyUtil.FILENAME); replacement.append(HttpPostBodyUtil.FILENAME);
replacement.append("=\""); replacement.append("=\"");
@ -593,6 +598,8 @@ public class HttpPostRequestEncoder implements ChunkedInput<HttpContent> {
replacement.append("\"\r\n"); replacement.append("\"\r\n");
pastAttribute.setValue(replacement.toString(), 1); pastAttribute.setValue(replacement.toString(), 1);
pastAttribute.setValue("", 2);
// update past size // update past size
globalBodySize += pastAttribute.size(); globalBodySize += pastAttribute.size();
@ -617,7 +624,7 @@ public class HttpPostRequestEncoder implements ChunkedInput<HttpContent> {
// Data to multipart list // Data to multipart list
internal.addValue("--" + multipartMixedBoundary + "\r\n"); internal.addValue("--" + multipartMixedBoundary + "\r\n");
// Content-Disposition: file; filename="file1.txt" // Content-Disposition: file; filename="file1.txt"
internal.addValue(HttpPostBodyUtil.CONTENT_DISPOSITION + ": " + HttpPostBodyUtil.FILE + "; " internal.addValue(HttpPostBodyUtil.CONTENT_DISPOSITION + ": " + HttpPostBodyUtil.ATTACHMENT + "; "
+ HttpPostBodyUtil.FILENAME + "=\"" + fileUpload.getFilename() + "\"\r\n"); + HttpPostBodyUtil.FILENAME + "=\"" + fileUpload.getFilename() + "\"\r\n");
} else { } else {
internal.addValue("--" + multipartDataBoundary + "\r\n"); internal.addValue("--" + multipartDataBoundary + "\r\n");

View File

@ -0,0 +1 @@
File 01

View File

@ -0,0 +1 @@
File 02