Removed code duplication

This commit is contained in:
Trustin Lee 2009-03-30 02:19:11 +00:00
parent c6b707c442
commit 4a27c83c04
2 changed files with 5 additions and 16 deletions

View File

@ -65,7 +65,7 @@ public class HttpChunkAggregator extends SimpleChannelUpstreamHandler {
HttpMessage currentMessage = this.currentMessage;
if (currentMessage == null) {
HttpMessage m = (HttpMessage) msg;
if (!isContentAlwaysEmpty(m) && m.isChunked()) {
if (m.isChunked()) {
// A chunked message - remove 'Transfer-Encoding' header,
// initialize the cumulative buffer, and wait for incoming chunks.
List<String> encodings = m.getHeaders(HttpHeaders.Names.TRANSFER_ENCODING);
@ -100,19 +100,4 @@ public class HttpChunkAggregator extends SimpleChannelUpstreamHandler {
}
}
}
protected boolean isContentAlwaysEmpty(HttpMessage msg) {
if (msg instanceof HttpResponse) {
HttpResponse res = (HttpResponse) msg;
int code = res.getStatus().getCode();
if (code < 200) {
return true;
}
switch (code) {
case 204: case 205: case 304:
return true;
}
}
return false;
}
}

View File

@ -138,6 +138,10 @@ public abstract class HttpMessageDecoder extends ReplayingDecoder<HttpMessageDec
return message;
} else if (nextState == State.SKIP_CONTROL_CHARS) {
// No content is expected.
// Remove the headers which are not supposed to be present not
// to confuse subsequent handlers.
message.removeHeader(HttpHeaders.Names.CONTENT_LENGTH);
message.removeHeader(HttpHeaders.Names.TRANSFER_ENCODING);
return message;
} else {
int contentLength = message.getContentLength(-1);