More robust HTTP message decoding
This commit is contained in:
parent
9cdc4a959e
commit
1243baa05b
@ -91,6 +91,7 @@ public abstract class HttpMessageDecoder extends ReplayingDecoder<HttpMessageDec
|
|||||||
case READ_HEADER: {
|
case READ_HEADER: {
|
||||||
readHeaders(buffer);
|
readHeaders(buffer);
|
||||||
if (message.isChunked()) {
|
if (message.isChunked()) {
|
||||||
|
System.err.println("CHUNKED!");
|
||||||
checkpoint(State.READ_CHUNK_SIZE);
|
checkpoint(State.READ_CHUNK_SIZE);
|
||||||
} else if (message.getContentLength() == 0) {
|
} else if (message.getContentLength() == 0) {
|
||||||
content = ChannelBuffers.EMPTY_BUFFER;
|
content = ChannelBuffers.EMPTY_BUFFER;
|
||||||
@ -221,7 +222,11 @@ public abstract class HttpMessageDecoder extends ReplayingDecoder<HttpMessageDec
|
|||||||
protected abstract void readInitial(ChannelBuffer buffer) throws Exception;
|
protected abstract void readInitial(ChannelBuffer buffer) throws Exception;
|
||||||
|
|
||||||
private int getChunkSize(String hex) {
|
private int getChunkSize(String hex) {
|
||||||
return Integer.valueOf(hex, 16);
|
int delimPos = hex.indexOf(';');
|
||||||
|
if (delimPos >= 0) {
|
||||||
|
hex = hex.substring(delimPos).trim();
|
||||||
|
}
|
||||||
|
return Integer.parseInt(hex, 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String readIntoCurrentLine(ChannelBuffer channel) {
|
protected String readIntoCurrentLine(ChannelBuffer channel) {
|
||||||
|
@ -36,10 +36,9 @@ public class HttpRequestDecoder extends HttpMessageDecoder {
|
|||||||
@Override
|
@Override
|
||||||
protected void readInitial(ChannelBuffer buffer) throws Exception{
|
protected void readInitial(ChannelBuffer buffer) throws Exception{
|
||||||
String line = readIntoCurrentLine(buffer);
|
String line = readIntoCurrentLine(buffer);
|
||||||
checkpoint(State.READ_HEADER);
|
|
||||||
String[] split = splitInitial(line);
|
String[] split = splitInitial(line);
|
||||||
message = new DefaultHttpRequest(
|
message = new DefaultHttpRequest(
|
||||||
HttpVersion.valueOf(split[2]), HttpMethod.valueOf(split[0]), split[1]);
|
HttpVersion.valueOf(split[2]), HttpMethod.valueOf(split[0]), split[1]);
|
||||||
|
checkpoint(State.READ_HEADER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,8 +35,8 @@ public class HttpResponseDecoder extends HttpMessageDecoder {
|
|||||||
@Override
|
@Override
|
||||||
protected void readInitial(ChannelBuffer buffer) {
|
protected void readInitial(ChannelBuffer buffer) {
|
||||||
String line = readIntoCurrentLine(buffer);
|
String line = readIntoCurrentLine(buffer);
|
||||||
checkpoint(State.READ_HEADER);
|
|
||||||
String[] split = splitInitial(line);
|
String[] split = splitInitial(line);
|
||||||
message = new DefaultHttpResponse(HttpVersion.valueOf(split[0]), new HttpResponseStatus(Integer.valueOf(split[1]), split[2]));
|
message = new DefaultHttpResponse(HttpVersion.valueOf(split[0]), new HttpResponseStatus(Integer.valueOf(split[1]), split[2]));
|
||||||
|
checkpoint(State.READ_HEADER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user