Fixed issue: NETTY-174 Always use 'ASCII' charset when encoding HTTP messages.

This commit is contained in:
Trustin Lee 2009-06-15 07:50:53 +00:00
parent e39d8720d2
commit d76bfe72b5
3 changed files with 28 additions and 17 deletions

View File

@ -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<String> headers = message.getHeaderNames();
for (String header : headers) {
List<String> values = message.getHeaders(header);
for (String value : values) {
try {
for (String header : headers) {
List<String> 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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}
}