Fixed issue: NETTY-174 Always use 'ASCII' charset when encoding HTTP messages.
This commit is contained in:
parent
e39d8720d2
commit
d76bfe72b5
@ -24,6 +24,7 @@ package org.jboss.netty.handler.codec.http;
|
|||||||
import static org.jboss.netty.buffer.ChannelBuffers.*;
|
import static org.jboss.netty.buffer.ChannelBuffers.*;
|
||||||
import static org.jboss.netty.handler.codec.http.HttpCodecUtil.*;
|
import static org.jboss.netty.handler.codec.http.HttpCodecUtil.*;
|
||||||
|
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@ -95,17 +96,21 @@ public abstract class HttpMessageEncoder extends OneToOneEncoder {
|
|||||||
*/
|
*/
|
||||||
public void encodeHeaders(ChannelBuffer buf, HttpMessage message) {
|
public void encodeHeaders(ChannelBuffer buf, HttpMessage message) {
|
||||||
Set<String> headers = message.getHeaderNames();
|
Set<String> headers = message.getHeaderNames();
|
||||||
|
try {
|
||||||
for (String header : headers) {
|
for (String header : headers) {
|
||||||
List<String> values = message.getHeaders(header);
|
List<String> values = message.getHeaders(header);
|
||||||
for (String value : values) {
|
for (String value : values) {
|
||||||
|
|
||||||
buf.writeBytes(header.getBytes());
|
buf.writeBytes(header.getBytes("ASCII"));
|
||||||
buf.writeByte(COLON);
|
buf.writeByte(COLON);
|
||||||
buf.writeByte(SP);
|
buf.writeByte(SP);
|
||||||
buf.writeBytes(value.getBytes());
|
buf.writeBytes(value.getBytes("ASCII"));
|
||||||
buf.writeBytes(CRLF);
|
buf.writeBytes(CRLF);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
throw (Error) new Error().initCause(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void encodeInitialLine(ChannelBuffer buf, HttpMessage message) throws Exception;
|
protected abstract void encodeInitialLine(ChannelBuffer buf, HttpMessage message) throws Exception;
|
||||||
|
@ -40,11 +40,11 @@ public class HttpRequestEncoder extends HttpMessageEncoder {
|
|||||||
@Override
|
@Override
|
||||||
protected void encodeInitialLine(ChannelBuffer buf, HttpMessage message) throws Exception {
|
protected void encodeInitialLine(ChannelBuffer buf, HttpMessage message) throws Exception {
|
||||||
HttpRequest request = (HttpRequest) message;
|
HttpRequest request = (HttpRequest) message;
|
||||||
buf.writeBytes(request.getMethod().toString().getBytes());
|
buf.writeBytes(request.getMethod().toString().getBytes("ASCII"));
|
||||||
buf.writeByte(SP);
|
buf.writeByte(SP);
|
||||||
buf.writeBytes(request.getUri().getBytes());
|
buf.writeBytes(request.getUri().getBytes("ASCII"));
|
||||||
buf.writeByte(SP);
|
buf.writeByte(SP);
|
||||||
buf.writeBytes(request.getProtocolVersion().toString().getBytes());
|
buf.writeBytes(request.getProtocolVersion().toString().getBytes("ASCII"));
|
||||||
buf.writeBytes(CRLF);
|
buf.writeBytes(CRLF);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,8 @@ package org.jboss.netty.handler.codec.http;
|
|||||||
|
|
||||||
import static org.jboss.netty.handler.codec.http.HttpCodecUtil.*;
|
import static org.jboss.netty.handler.codec.http.HttpCodecUtil.*;
|
||||||
|
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
|
||||||
import org.jboss.netty.buffer.ChannelBuffer;
|
import org.jboss.netty.buffer.ChannelBuffer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -38,12 +40,16 @@ public class HttpResponseEncoder extends HttpMessageEncoder {
|
|||||||
@Override
|
@Override
|
||||||
protected void encodeInitialLine(ChannelBuffer buf, HttpMessage message) {
|
protected void encodeInitialLine(ChannelBuffer buf, HttpMessage message) {
|
||||||
HttpResponse response = (HttpResponse) message;
|
HttpResponse response = (HttpResponse) message;
|
||||||
buf.writeBytes(response.getProtocolVersion().toString().getBytes());
|
try {
|
||||||
|
buf.writeBytes(response.getProtocolVersion().toString().getBytes("ASCII"));
|
||||||
buf.writeByte(SP);
|
buf.writeByte(SP);
|
||||||
buf.writeBytes(String.valueOf(response.getStatus().getCode()).getBytes());
|
buf.writeBytes(String.valueOf(response.getStatus().getCode()).getBytes("ASCII"));
|
||||||
buf.writeByte(SP);
|
buf.writeByte(SP);
|
||||||
buf.writeBytes(String.valueOf(response.getStatus().getReasonPhrase()).getBytes());
|
buf.writeBytes(String.valueOf(response.getStatus().getReasonPhrase()).getBytes("ASCII"));
|
||||||
buf.writeBytes(CRLF);
|
buf.writeBytes(CRLF);
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
throw (Error) new Error().initCause(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user