Maintain decoder result in HttpObjectAggregator

Motivation:
DecodeResult is dropped when aggregate HTTP messages.

Modification:

Make sure we not drop the DecodeResult while aggregate HTTP messages.

Result:

Correctly include the DecodeResult for later processing.
This commit is contained in:
Jay 2014-06-28 00:27:21 -04:00 committed by Norman Maurer
parent cb1143ec20
commit 0332fd1589
2 changed files with 8 additions and 2 deletions

View File

@ -260,10 +260,12 @@ public class HttpObjectAggregator extends MessageToMessageDecoder<HttpObject> {
HttpRequest req = (HttpRequest) msg; HttpRequest req = (HttpRequest) msg;
fullMsg = new DefaultFullHttpRequest( fullMsg = new DefaultFullHttpRequest(
req.getProtocolVersion(), req.getMethod(), req.getUri(), Unpooled.EMPTY_BUFFER, false); req.getProtocolVersion(), req.getMethod(), req.getUri(), Unpooled.EMPTY_BUFFER, false);
fullMsg.setDecoderResult(req.getDecoderResult());
} else if (msg instanceof HttpResponse) { } else if (msg instanceof HttpResponse) {
HttpResponse res = (HttpResponse) msg; HttpResponse res = (HttpResponse) msg;
fullMsg = new DefaultFullHttpResponse( fullMsg = new DefaultFullHttpResponse(
res.getProtocolVersion(), res.getStatus(), Unpooled.EMPTY_BUFFER, false); res.getProtocolVersion(), res.getStatus(), Unpooled.EMPTY_BUFFER, false);
fullMsg.setDecoderResult(res.getDecoderResult());
} else { } else {
throw new IllegalStateException(); throw new IllegalStateException();
} }

View File

@ -192,7 +192,9 @@ public class HttpObjectAggregatorTest {
public void testBadRequest() { public void testBadRequest() {
EmbeddedChannel ch = new EmbeddedChannel(new HttpRequestDecoder(), new HttpObjectAggregator(1024 * 1024)); EmbeddedChannel ch = new EmbeddedChannel(new HttpRequestDecoder(), new HttpObjectAggregator(1024 * 1024));
ch.writeInbound(Unpooled.copiedBuffer("GET / HTTP/1.0 with extra\r\n", CharsetUtil.UTF_8)); ch.writeInbound(Unpooled.copiedBuffer("GET / HTTP/1.0 with extra\r\n", CharsetUtil.UTF_8));
assertThat(ch.readInbound(), is(instanceOf(FullHttpRequest.class))); Object inbound = ch.readInbound();
assertThat(inbound, is(instanceOf(FullHttpRequest.class)));
assertTrue(((FullHttpRequest) inbound).getDecoderResult().isFailure());
assertNull(ch.readInbound()); assertNull(ch.readInbound());
ch.finish(); ch.finish();
} }
@ -201,7 +203,9 @@ public class HttpObjectAggregatorTest {
public void testBadResponse() throws Exception { public void testBadResponse() throws Exception {
EmbeddedChannel ch = new EmbeddedChannel(new HttpResponseDecoder(), new HttpObjectAggregator(1024 * 1024)); EmbeddedChannel ch = new EmbeddedChannel(new HttpResponseDecoder(), new HttpObjectAggregator(1024 * 1024));
ch.writeInbound(Unpooled.copiedBuffer("HTTP/1.0 BAD_CODE Bad Server\r\n", CharsetUtil.UTF_8)); ch.writeInbound(Unpooled.copiedBuffer("HTTP/1.0 BAD_CODE Bad Server\r\n", CharsetUtil.UTF_8));
assertThat(ch.readInbound(), is(instanceOf(FullHttpResponse.class))); Object inbound = ch.readInbound();
assertThat(inbound, is(instanceOf(FullHttpResponse.class)));
assertTrue(((FullHttpResponse) inbound).getDecoderResult().isFailure());
assertNull(ch.readInbound()); assertNull(ch.readInbound());
ch.finish(); ch.finish();
} }