Removed code duplication
This commit is contained in:
parent
c6b707c442
commit
4a27c83c04
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user