AggregatedFullHttpMessage.replace should also copy a decoder result
Motivation: HttpObjectAggregator yields full HTTP messgaes (AggregatedFullHttpMessages) that don't respect decoder result when copied/replaced. Modifications: Copy the decoding result over to a new instance produced by AggregatedFullHttpRequest.replace or AggregatedFullHttpResponse.replace . Result: DecoderResult is now copied over when an original AggregatedFullHttpMessage is being replaced (i.e., AggregatedFullHttpRequest.replace or AggregatedFullHttpResponse.replace is being called). New unit tests are passing on this branch but are failing on master.
This commit is contained in:
parent
b9abd3c9fc
commit
0f9b739508
@ -404,6 +404,7 @@ public class HttpObjectAggregator
|
||||
DefaultFullHttpRequest dup = new DefaultFullHttpRequest(protocolVersion(), method(), uri(), content);
|
||||
dup.headers().set(headers());
|
||||
dup.trailingHeaders().set(trailingHeaders());
|
||||
dup.setDecoderResult(decoderResult());
|
||||
return dup;
|
||||
}
|
||||
|
||||
@ -502,6 +503,7 @@ public class HttpObjectAggregator
|
||||
DefaultFullHttpResponse dup = new DefaultFullHttpResponse(getProtocolVersion(), getStatus(), content);
|
||||
dup.headers().set(headers());
|
||||
dup.trailingHeaders().set(trailingHeaders());
|
||||
dup.setDecoderResult(decoderResult());
|
||||
return dup;
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,7 @@ import io.netty.buffer.CompositeByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.embedded.EmbeddedChannel;
|
||||
import io.netty.handler.codec.DecoderResult;
|
||||
import io.netty.handler.codec.DecoderResultProvider;
|
||||
import io.netty.handler.codec.TooLongFrameException;
|
||||
import io.netty.util.CharsetUtil;
|
||||
@ -417,4 +418,40 @@ public class HttpObjectAggregatorTest {
|
||||
fullMsg.release();
|
||||
assertFalse(embedder.finish());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReplaceAggregatedRequest() {
|
||||
EmbeddedChannel embedder = new EmbeddedChannel(new HttpObjectAggregator(1024 * 1024));
|
||||
|
||||
Exception boom = new Exception("boom");
|
||||
HttpRequest req = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "http://localhost");
|
||||
req.setDecoderResult(DecoderResult.failure(boom));
|
||||
|
||||
assertTrue(embedder.writeInbound(req) && embedder.finish());
|
||||
|
||||
FullHttpRequest aggregatedReq = embedder.readInbound();
|
||||
FullHttpRequest replacedReq = aggregatedReq.replace(Unpooled.EMPTY_BUFFER);
|
||||
|
||||
assertEquals(replacedReq.decoderResult(), aggregatedReq.decoderResult());
|
||||
aggregatedReq.release();
|
||||
replacedReq.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReplaceAggregatedResponse() {
|
||||
EmbeddedChannel embedder = new EmbeddedChannel(new HttpObjectAggregator(1024 * 1024));
|
||||
|
||||
Exception boom = new Exception("boom");
|
||||
HttpResponse rep = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
|
||||
rep.setDecoderResult(DecoderResult.failure(boom));
|
||||
|
||||
assertTrue(embedder.writeInbound(rep) && embedder.finish());
|
||||
|
||||
FullHttpResponse aggregatedRep = embedder.readInbound();
|
||||
FullHttpResponse replacedRep = aggregatedRep.replace(Unpooled.EMPTY_BUFFER);
|
||||
|
||||
assertEquals(replacedRep.decoderResult(), aggregatedRep.decoderResult());
|
||||
aggregatedRep.release();
|
||||
replacedRep.release();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user