diff --git a/src/main/java/org/jboss/netty/handler/codec/http/HttpMessageEncoder.java b/src/main/java/org/jboss/netty/handler/codec/http/HttpMessageEncoder.java index 82325dc2a0..90691a3d69 100644 --- a/src/main/java/org/jboss/netty/handler/codec/http/HttpMessageEncoder.java +++ b/src/main/java/org/jboss/netty/handler/codec/http/HttpMessageEncoder.java @@ -24,6 +24,7 @@ package org.jboss.netty.handler.codec.http; import static org.jboss.netty.buffer.ChannelBuffers.*; import static org.jboss.netty.handler.codec.http.HttpCodecUtil.*; +import java.io.UnsupportedEncodingException; import java.util.List; import java.util.Set; @@ -95,16 +96,20 @@ public abstract class HttpMessageEncoder extends OneToOneEncoder { */ public void encodeHeaders(ChannelBuffer buf, HttpMessage message) { Set headers = message.getHeaderNames(); - for (String header : headers) { - List values = message.getHeaders(header); - for (String value : values) { + try { + for (String header : headers) { + List values = message.getHeaders(header); + for (String value : values) { - buf.writeBytes(header.getBytes()); - buf.writeByte(COLON); - buf.writeByte(SP); - buf.writeBytes(value.getBytes()); - buf.writeBytes(CRLF); + buf.writeBytes(header.getBytes("ASCII")); + buf.writeByte(COLON); + buf.writeByte(SP); + buf.writeBytes(value.getBytes("ASCII")); + buf.writeBytes(CRLF); + } } + } catch (UnsupportedEncodingException e) { + throw (Error) new Error().initCause(e); } } diff --git a/src/main/java/org/jboss/netty/handler/codec/http/HttpRequestEncoder.java b/src/main/java/org/jboss/netty/handler/codec/http/HttpRequestEncoder.java index cb3984201e..92b158a9ed 100644 --- a/src/main/java/org/jboss/netty/handler/codec/http/HttpRequestEncoder.java +++ b/src/main/java/org/jboss/netty/handler/codec/http/HttpRequestEncoder.java @@ -40,11 +40,11 @@ public class HttpRequestEncoder extends HttpMessageEncoder { @Override protected void encodeInitialLine(ChannelBuffer buf, HttpMessage message) throws Exception { HttpRequest request = (HttpRequest) message; - buf.writeBytes(request.getMethod().toString().getBytes()); + buf.writeBytes(request.getMethod().toString().getBytes("ASCII")); buf.writeByte(SP); - buf.writeBytes(request.getUri().getBytes()); + buf.writeBytes(request.getUri().getBytes("ASCII")); buf.writeByte(SP); - buf.writeBytes(request.getProtocolVersion().toString().getBytes()); + buf.writeBytes(request.getProtocolVersion().toString().getBytes("ASCII")); buf.writeBytes(CRLF); } } diff --git a/src/main/java/org/jboss/netty/handler/codec/http/HttpResponseEncoder.java b/src/main/java/org/jboss/netty/handler/codec/http/HttpResponseEncoder.java index df3681863b..6c61e91f23 100644 --- a/src/main/java/org/jboss/netty/handler/codec/http/HttpResponseEncoder.java +++ b/src/main/java/org/jboss/netty/handler/codec/http/HttpResponseEncoder.java @@ -23,6 +23,8 @@ package org.jboss.netty.handler.codec.http; import static org.jboss.netty.handler.codec.http.HttpCodecUtil.*; +import java.io.UnsupportedEncodingException; + import org.jboss.netty.buffer.ChannelBuffer; /** @@ -38,12 +40,16 @@ public class HttpResponseEncoder extends HttpMessageEncoder { @Override protected void encodeInitialLine(ChannelBuffer buf, HttpMessage message) { HttpResponse response = (HttpResponse) message; - buf.writeBytes(response.getProtocolVersion().toString().getBytes()); - buf.writeByte(SP); - buf.writeBytes(String.valueOf(response.getStatus().getCode()).getBytes()); - buf.writeByte(SP); - buf.writeBytes(String.valueOf(response.getStatus().getReasonPhrase()).getBytes()); - buf.writeBytes(CRLF); + try { + buf.writeBytes(response.getProtocolVersion().toString().getBytes("ASCII")); + buf.writeByte(SP); + buf.writeBytes(String.valueOf(response.getStatus().getCode()).getBytes("ASCII")); + buf.writeByte(SP); + buf.writeBytes(String.valueOf(response.getStatus().getReasonPhrase()).getBytes("ASCII")); + buf.writeBytes(CRLF); + } catch (UnsupportedEncodingException e) { + throw (Error) new Error().initCause(e); + } } }