Fix IndexOutOfBoundsException in HelloWorldHttp2Handler

Motivation:

We need to duplicate the buffer before passing it to writeBytes(...) as it will increase the readerIndex().

Modifications:

Call duplicate().

Result:

No more IndexOutOfBoundsException when runing the multiplex example.
This commit is contained in:
Norman Maurer 2016-09-08 06:51:43 +02:00
parent e94db103c9
commit 4a5340eae7

View File

@ -76,7 +76,7 @@ public class HelloWorldHttp2Handler extends ChannelDuplexHandler {
throws Exception {
if (headers.isEndStream()) {
ByteBuf content = ctx.alloc().buffer();
content.writeBytes(RESPONSE_BYTES);
content.writeBytes(RESPONSE_BYTES.duplicate());
ByteBufUtil.writeAscii(content, " - via HTTP/2");
sendResponse(ctx, content);
}