diff --git a/src/main/java/org/jboss/netty/handler/codec/http/multipart/HttpPostRequestEncoder.java b/src/main/java/org/jboss/netty/handler/codec/http/multipart/HttpPostRequestEncoder.java index 29fecaaac6..33d2a2f9e9 100644 --- a/src/main/java/org/jboss/netty/handler/codec/http/multipart/HttpPostRequestEncoder.java +++ b/src/main/java/org/jboss/netty/handler/codec/http/multipart/HttpPostRequestEncoder.java @@ -440,14 +440,14 @@ public class HttpPostRequestEncoder implements ChunkedInput { */ if (data instanceof Attribute) { if (duringMixedMode) { - InternalAttribute internal = new InternalAttribute(); + InternalAttribute internal = new InternalAttribute(charset); internal.addValue("\r\n--" + multipartMixedBoundary + "--"); multipartHttpDatas.add(internal); multipartMixedBoundary = null; currentFileUpload = null; duringMixedMode = false; } - InternalAttribute internal = new InternalAttribute(); + InternalAttribute internal = new InternalAttribute(charset); if (!multipartHttpDatas.isEmpty()) { // previously a data field so CRLF internal.addValue("\r\n"); @@ -472,7 +472,7 @@ public class HttpPostRequestEncoder implements ChunkedInput { globalBodySize += attribute.length() + internal.size(); } else if (data instanceof FileUpload) { FileUpload fileUpload = (FileUpload) data; - InternalAttribute internal = new InternalAttribute(); + InternalAttribute internal = new InternalAttribute(charset); if (!multipartHttpDatas.isEmpty()) { // previously a data field so CRLF internal.addValue("\r\n"); @@ -493,7 +493,7 @@ public class HttpPostRequestEncoder implements ChunkedInput { multipartHttpDatas.add(internal); multipartMixedBoundary = null; // start a new one (could be replaced if mixed start again from here - internal = new InternalAttribute(); + internal = new InternalAttribute(charset); internal.addValue("\r\n"); localMixed = false; // new currentFileUpload and no more in Mixed mode @@ -617,7 +617,7 @@ public class HttpPostRequestEncoder implements ChunkedInput { // Finalize the multipartHttpDatas if (! headerFinalized) { if (isMultipart) { - InternalAttribute internal = new InternalAttribute(); + InternalAttribute internal = new InternalAttribute(charset); if (duringMixedMode) { internal.addValue("\r\n--" + multipartMixedBoundary + "--"); } @@ -771,14 +771,8 @@ public class HttpPostRequestEncoder implements ChunkedInput { } ChannelBuffer buffer; if (currentData instanceof InternalAttribute) { - String internal = currentData.toString(); - byte[] bytes; - try { - bytes = internal.getBytes("ASCII"); - } catch (UnsupportedEncodingException e) { - throw new ErrorDataEncoderException(e); - } - buffer = ChannelBuffers.wrappedBuffer(bytes); + + buffer = ((InternalAttribute) currentData).toChannelBuffer(); currentData = null; } else { if (currentData instanceof Attribute) { diff --git a/src/main/java/org/jboss/netty/handler/codec/http/multipart/InternalAttribute.java b/src/main/java/org/jboss/netty/handler/codec/http/multipart/InternalAttribute.java index efebc09768..5eaa11b29e 100644 --- a/src/main/java/org/jboss/netty/handler/codec/http/multipart/InternalAttribute.java +++ b/src/main/java/org/jboss/netty/handler/codec/http/multipart/InternalAttribute.java @@ -15,6 +15,12 @@ */ package org.jboss.netty.handler.codec.http.multipart; +import org.jboss.netty.buffer.ChannelBuffer; +import org.jboss.netty.buffer.ChannelBuffers; +import org.jboss.netty.util.CharsetUtil; + +import java.io.UnsupportedEncodingException; +import java.nio.charset.Charset; import java.util.ArrayList; import java.util.List; @@ -23,12 +29,25 @@ import java.util.List; * (like Multipart Mixed mode) */ public class InternalAttribute implements InterfaceHttpData { + @Deprecated protected final List value = new ArrayList(); + private final Charset charset; + + @Deprecated + public InternalAttribute() { + this(CharsetUtil.UTF_8); + } + + @Deprecated + public InternalAttribute(Charset charset) { + this.charset = charset; + } public HttpDataType getHttpDataType() { return HttpDataType.InternalAttribute; } + @Deprecated public List getValue() { return value; } @@ -83,7 +102,11 @@ public class InternalAttribute implements InterfaceHttpData { public int size() { int size = 0; for (String elt : value) { - size += elt.length(); + try { + size += elt.getBytes(charset.name()).length; + } catch (UnsupportedEncodingException e) { + throw new RuntimeException(e); + } } return size; } @@ -96,6 +119,14 @@ public class InternalAttribute implements InterfaceHttpData { return result.toString(); } + public ChannelBuffer toChannelBuffer() { + ChannelBuffer[] buffers = new ChannelBuffer[value.size()]; + for (int i = 0; i < buffers.length; i++) { + buffers[i] = ChannelBuffers.copiedBuffer(value.get(i), charset); + } + return ChannelBuffers.wrappedBuffer(buffers); + } + public String getName() { return "InternalAttribute"; }