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;
|
HttpMessage currentMessage = this.currentMessage;
|
||||||
if (currentMessage == null) {
|
if (currentMessage == null) {
|
||||||
HttpMessage m = (HttpMessage) msg;
|
HttpMessage m = (HttpMessage) msg;
|
||||||
if (!isContentAlwaysEmpty(m) && m.isChunked()) {
|
if (m.isChunked()) {
|
||||||
// A chunked message - remove 'Transfer-Encoding' header,
|
// A chunked message - remove 'Transfer-Encoding' header,
|
||||||
// initialize the cumulative buffer, and wait for incoming chunks.
|
// initialize the cumulative buffer, and wait for incoming chunks.
|
||||||
List<String> encodings = m.getHeaders(HttpHeaders.Names.TRANSFER_ENCODING);
|
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;
|
return message;
|
||||||
} else if (nextState == State.SKIP_CONTROL_CHARS) {
|
} else if (nextState == State.SKIP_CONTROL_CHARS) {
|
||||||
// No content is expected.
|
// 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;
|
return message;
|
||||||
} else {
|
} else {
|
||||||
int contentLength = message.getContentLength(-1);
|
int contentLength = message.getContentLength(-1);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user