Fixed issue: NETTY-107 - HttpMessageDecoder can not handle the content with no 'Content-Length' header.

This commit is contained in:
Trustin Lee 2009-02-12 07:32:53 +00:00
parent 2d682dc2a3
commit 431151b8e5
3 changed files with 17 additions and 3 deletions

View File

@ -103,9 +103,12 @@ public abstract class HttpMessageDecoder extends ReplayingDecoder<HttpMessageDec
if (!mergeChunks) { if (!mergeChunks) {
return message; return message;
} }
} else if (message.getContentLength(-1) == 0) { } else {
content = ChannelBuffers.EMPTY_BUFFER; int contentLength = message.getContentLength(-1);
return reset(); if (contentLength == 0 || contentLength == -1 && isDecodingRequest()) {
content = ChannelBuffers.EMPTY_BUFFER;
return reset();
}
} }
//we return null here, this forces decode to be called again where we will decode the content //we return null here, this forces decode to be called again where we will decode the content
return null; return null;
@ -246,6 +249,7 @@ public abstract class HttpMessageDecoder extends ReplayingDecoder<HttpMessageDec
checkpoint(nextState); checkpoint(nextState);
} }
protected abstract boolean isDecodingRequest();
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) {

View File

@ -49,4 +49,9 @@ public class HttpRequestDecoder extends HttpMessageDecoder {
HttpVersion.valueOf(split[2]), HttpMethod.valueOf(split[0]), split[1]); HttpVersion.valueOf(split[2]), HttpMethod.valueOf(split[0]), split[1]);
checkpoint(State.READ_HEADER); checkpoint(State.READ_HEADER);
} }
@Override
protected boolean isDecodingRequest() {
return true;
}
} }

View File

@ -48,4 +48,9 @@ public class HttpResponseDecoder extends HttpMessageDecoder {
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); checkpoint(State.READ_HEADER);
} }
@Override
protected boolean isDecodingRequest() {
return false;
}
} }