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: {
|
||||
readHeaders(buffer);
|
||||
if (message.isChunked()) {
|
||||
System.err.println("CHUNKED!");
|
||||
checkpoint(State.READ_CHUNK_SIZE);
|
||||
} else if (message.getContentLength() == 0) {
|
||||
content = ChannelBuffers.EMPTY_BUFFER;
|
||||
@ -221,7 +222,11 @@ public abstract class HttpMessageDecoder extends ReplayingDecoder<HttpMessageDec
|
||||
protected abstract void readInitial(ChannelBuffer buffer) throws Exception;
|
||||
|
||||
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) {
|
||||
|
@ -36,10 +36,9 @@ public class HttpRequestDecoder extends HttpMessageDecoder {
|
||||
@Override
|
||||
protected void readInitial(ChannelBuffer buffer) throws Exception{
|
||||
String line = readIntoCurrentLine(buffer);
|
||||
checkpoint(State.READ_HEADER);
|
||||
String[] split = splitInitial(line);
|
||||
message = new DefaultHttpRequest(
|
||||
HttpVersion.valueOf(split[2]), HttpMethod.valueOf(split[0]), split[1]);
|
||||
|
||||
checkpoint(State.READ_HEADER);
|
||||
}
|
||||
}
|
||||
|
@ -35,8 +35,8 @@ public class HttpResponseDecoder extends HttpMessageDecoder {
|
||||
@Override
|
||||
protected void readInitial(ChannelBuffer buffer) {
|
||||
String line = readIntoCurrentLine(buffer);
|
||||
checkpoint(State.READ_HEADER);
|
||||
String[] split = splitInitial(line);
|
||||
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