From d5148bfee92a78cb38f029d2d0612c7e34992d9b Mon Sep 17 00:00:00 2001 From: nmittler Date: Thu, 8 May 2014 07:26:55 -0700 Subject: [PATCH] Adding context to Http2FrameObserver Motivation: The Http2FrameObserver isn't provided the ChannelHandlerContext when it's called back. This will force observers to find an alternative means of obtaining the context if they need to do things like copying buffers. Modifications: Changed the Http2FrameReader and Http2FrameObserver to include the context. Updated all other uses of these interfaces. Result: Frame observers will now have the channel context. --- .../http2/AbstractHttp2ConnectionHandler.java | 82 ++++----- .../codec/http2/DefaultHttp2FrameReader.java | 97 +++++----- .../DelegatingHttp2ConnectionHandler.java | 110 ++++++------ .../codec/http2/Http2FrameObserver.java | 74 +++++--- .../handler/codec/http2/Http2FrameReader.java | 4 +- .../codec/http2/Http2InboundFrameLogger.java | 130 +++++++------- .../codec/http2/DefaultHttp2FrameIOTest.java | 112 ++++++------ .../DelegatingHttp2ConnectionHandlerTest.java | 116 ++++++------ .../http2/Http2ConnectionRoundtripTest.java | 169 +++++++++--------- .../codec/http2/Http2FrameRoundtripTest.java | 131 ++++++++------ .../client/Http2ClientConnectionHandler.java | 63 +++---- .../http2/server/HelloWorldHttp2Handler.java | 57 +++--- 12 files changed, 599 insertions(+), 546 deletions(-) diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/AbstractHttp2ConnectionHandler.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/AbstractHttp2ConnectionHandler.java index fe695f47d7..fc05e1299f 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/AbstractHttp2ConnectionHandler.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/AbstractHttp2ConnectionHandler.java @@ -366,7 +366,7 @@ public abstract class AbstractHttp2ConnectionHandler extends ByteToMessageDecode protected final void decode(ChannelHandlerContext ctx, ByteBuf in, List out) throws Exception { try { - frameReader.readFrame(ctx.alloc(), in, internalFrameObserver); + frameReader.readFrame(ctx, in, internalFrameObserver); } catch (Http2Exception e) { processHttp2Exception(ctx, e); } @@ -514,8 +514,8 @@ public abstract class AbstractHttp2ConnectionHandler extends ByteToMessageDecode private final class FrameReadObserver implements Http2FrameObserver { @Override - public void onDataRead(int streamId, ByteBuf data, int padding, boolean endOfStream, - boolean endOfSegment, boolean compressed) throws Http2Exception { + public void onDataRead(final ChannelHandlerContext ctx, int streamId, ByteBuf data, int padding, + boolean endOfStream, boolean endOfSegment, boolean compressed) throws Http2Exception { verifyInitialSettingsReceived(); if (!connection.local().allowCompressedData() && compressed) { @@ -546,22 +546,21 @@ public abstract class AbstractHttp2ConnectionHandler extends ByteToMessageDecode closeRemoteSide(stream, ctx, ctx.newSucceededFuture()); } - AbstractHttp2ConnectionHandler.this.onDataRead(streamId, data, padding, endOfStream, + AbstractHttp2ConnectionHandler.this.onDataRead(ctx, streamId, data, padding, endOfStream, endOfSegment, compressed); } @Override - public void onHeadersRead(int streamId, Http2Headers headers, int padding, - boolean endStream, boolean endSegment) throws Http2Exception { - onHeadersRead(streamId, headers, 0, DEFAULT_PRIORITY_WEIGHT, false, padding, endStream, - endSegment); + public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, + int padding, boolean endStream, boolean endSegment) throws Http2Exception { + onHeadersRead(ctx, streamId, headers, 0, DEFAULT_PRIORITY_WEIGHT, false, padding, + endStream, endSegment); } @Override - public void - onHeadersRead(int streamId, Http2Headers headers, int streamDependency, - short weight, boolean exclusive, int padding, boolean endStream, - boolean endSegment) throws Http2Exception { + public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, + int streamDependency, short weight, boolean exclusive, int padding, + boolean endStream, boolean endSegment) throws Http2Exception { verifyInitialSettingsReceived(); if (isInboundStreamAfterGoAway(streamId)) { @@ -607,13 +606,13 @@ public abstract class AbstractHttp2ConnectionHandler extends ByteToMessageDecode } } - AbstractHttp2ConnectionHandler.this.onHeadersRead(streamId, headers, streamDependency, + AbstractHttp2ConnectionHandler.this.onHeadersRead(ctx, streamId, headers, streamDependency, weight, exclusive, padding, endStream, endSegment); } @Override - public void onPriorityRead(int streamId, int streamDependency, short weight, - boolean exclusive) throws Http2Exception { + public void onPriorityRead(ChannelHandlerContext ctx, int streamId, int streamDependency, + short weight, boolean exclusive) throws Http2Exception { verifyInitialSettingsReceived(); if (isInboundStreamAfterGoAway(streamId)) { @@ -624,12 +623,13 @@ public abstract class AbstractHttp2ConnectionHandler extends ByteToMessageDecode // Set the priority for this stream on the flow controller. outboundFlow.updateStream(streamId, streamDependency, weight, exclusive); - AbstractHttp2ConnectionHandler.this.onPriorityRead(streamId, streamDependency, weight, - exclusive); + AbstractHttp2ConnectionHandler.this.onPriorityRead(ctx, streamId, streamDependency, + weight, exclusive); } @Override - public void onRstStreamRead(int streamId, long errorCode) throws Http2Exception { + public void onRstStreamRead(ChannelHandlerContext ctx, int streamId, long errorCode) + throws Http2Exception { verifyInitialSettingsReceived(); if (isInboundStreamAfterGoAway(streamId)) { @@ -645,18 +645,19 @@ public abstract class AbstractHttp2ConnectionHandler extends ByteToMessageDecode close(stream, ctx, ctx.newSucceededFuture()); - AbstractHttp2ConnectionHandler.this.onRstStreamRead(streamId, errorCode); + AbstractHttp2ConnectionHandler.this.onRstStreamRead(ctx, streamId, errorCode); } @Override - public void onSettingsAckRead() throws Http2Exception { + public void onSettingsAckRead(ChannelHandlerContext ctx) throws Http2Exception { verifyInitialSettingsReceived(); - AbstractHttp2ConnectionHandler.this.onSettingsAckRead(); + AbstractHttp2ConnectionHandler.this.onSettingsAckRead(ctx); } @Override - public void onSettingsRead(Http2Settings settings) throws Http2Exception { + public void onSettingsRead(ChannelHandlerContext ctx, Http2Settings settings) + throws Http2Exception { if (settings.hasAllowCompressedData()) { connection.remote().allowCompressedData(settings.allowCompressedData()); } @@ -683,29 +684,29 @@ public abstract class AbstractHttp2ConnectionHandler extends ByteToMessageDecode // We've received at least one non-ack settings frame from the remote endpoint. initialSettingsReceived = true; - AbstractHttp2ConnectionHandler.this.onSettingsRead(settings); + AbstractHttp2ConnectionHandler.this.onSettingsRead(ctx, settings); } @Override - public void onPingRead(ByteBuf data) throws Http2Exception { + public void onPingRead(ChannelHandlerContext ctx, ByteBuf data) throws Http2Exception { verifyInitialSettingsReceived(); // Send an ack back to the remote client. frameWriter.writePing(ctx, ctx.newPromise(), true, data); - AbstractHttp2ConnectionHandler.this.onPingRead(data); + AbstractHttp2ConnectionHandler.this.onPingRead(ctx, data); } @Override - public void onPingAckRead(ByteBuf data) throws Http2Exception { + public void onPingAckRead(ChannelHandlerContext ctx, ByteBuf data) throws Http2Exception { verifyInitialSettingsReceived(); - AbstractHttp2ConnectionHandler.this.onPingAckRead(data); + AbstractHttp2ConnectionHandler.this.onPingAckRead(ctx, data); } @Override - public void onPushPromiseRead(int streamId, int promisedStreamId, Http2Headers headers, - int padding) throws Http2Exception { + public void onPushPromiseRead(ChannelHandlerContext ctx, int streamId, + int promisedStreamId, Http2Headers headers, int padding) throws Http2Exception { verifyInitialSettingsReceived(); if (isInboundStreamAfterGoAway(streamId)) { @@ -717,21 +718,22 @@ public abstract class AbstractHttp2ConnectionHandler extends ByteToMessageDecode Http2Stream parentStream = connection.requireStream(streamId); connection.remote().reservePushStream(promisedStreamId, parentStream); - AbstractHttp2ConnectionHandler.this.onPushPromiseRead(streamId, promisedStreamId, + AbstractHttp2ConnectionHandler.this.onPushPromiseRead(ctx, streamId, promisedStreamId, headers, padding); } @Override - public void onGoAwayRead(int lastStreamId, long errorCode, ByteBuf debugData) + public void onGoAwayRead(ChannelHandlerContext ctx, int lastStreamId, long errorCode, ByteBuf debugData) throws Http2Exception { // Don't allow any more connections to be created. connection.goAwayReceived(); - AbstractHttp2ConnectionHandler.this.onGoAwayRead(lastStreamId, errorCode, debugData); + AbstractHttp2ConnectionHandler.this.onGoAwayRead(ctx, lastStreamId, errorCode, debugData); } @Override - public void onWindowUpdateRead(int streamId, int windowSizeIncrement) throws Http2Exception { + public void onWindowUpdateRead(ChannelHandlerContext ctx, int streamId, + int windowSizeIncrement) throws Http2Exception { verifyInitialSettingsReceived(); if (isInboundStreamAfterGoAway(streamId)) { @@ -751,18 +753,18 @@ public abstract class AbstractHttp2ConnectionHandler extends ByteToMessageDecode // Update the outbound flow controller. outboundFlow.updateOutboundWindowSize(streamId, windowSizeIncrement); - AbstractHttp2ConnectionHandler.this.onWindowUpdateRead(streamId, windowSizeIncrement); + AbstractHttp2ConnectionHandler.this.onWindowUpdateRead(ctx, streamId, windowSizeIncrement); } @Override - public void onAltSvcRead(int streamId, long maxAge, int port, ByteBuf protocolId, - String host, String origin) throws Http2Exception { - AbstractHttp2ConnectionHandler.this.onAltSvcRead(streamId, maxAge, port, protocolId, - host, origin); + public void onAltSvcRead(ChannelHandlerContext ctx, int streamId, long maxAge, int port, + ByteBuf protocolId, String host, String origin) throws Http2Exception { + AbstractHttp2ConnectionHandler.this.onAltSvcRead(ctx, streamId, maxAge, port, + protocolId, host, origin); } @Override - public void onBlockedRead(int streamId) throws Http2Exception { + public void onBlockedRead(ChannelHandlerContext ctx, int streamId) throws Http2Exception { verifyInitialSettingsReceived(); if (isInboundStreamAfterGoAway(streamId)) { @@ -782,7 +784,7 @@ public abstract class AbstractHttp2ConnectionHandler extends ByteToMessageDecode // Update the outbound flow controller. outboundFlow.setBlocked(streamId); - AbstractHttp2ConnectionHandler.this.onBlockedRead(streamId); + AbstractHttp2ConnectionHandler.this.onBlockedRead(ctx, streamId); } /** diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2FrameReader.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2FrameReader.java index 17edd0afe4..d9fd082b4d 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2FrameReader.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2FrameReader.java @@ -31,6 +31,7 @@ import static io.netty.handler.codec.http2.Http2Exception.protocolError; import static io.netty.util.CharsetUtil.UTF_8; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufAllocator; +import io.netty.channel.ChannelHandlerContext; /** * A {@link Http2FrameReader} that supports all frame types defined by the HTTP/2 specification. @@ -80,7 +81,7 @@ public class DefaultHttp2FrameReader implements Http2FrameReader { } @Override - public void readFrame(ByteBufAllocator alloc, ByteBuf input, Http2FrameObserver observer) + public void readFrame(ChannelHandlerContext ctx, ByteBuf input, Http2FrameObserver observer) throws Http2Exception { try { while (input.isReadable()) { @@ -98,7 +99,7 @@ public class DefaultHttp2FrameReader implements Http2FrameReader { // available, causing us to exit the loop. Instead, we just want to perform // the first pass at payload processing now. case FRAME_PAYLOAD: - processPayloadState(alloc, input, observer); + processPayloadState(ctx, input, observer); if (state == State.FRAME_PAYLOAD) { // Wait until the entire payload has arrived. return; @@ -181,7 +182,7 @@ public class DefaultHttp2FrameReader implements Http2FrameReader { } private void - processPayloadState(ByteBufAllocator alloc, ByteBuf in, Http2FrameObserver observer) + processPayloadState(ChannelHandlerContext ctx, ByteBuf in, Http2FrameObserver observer) throws Http2Exception { if (in.readableBytes() < payloadLength) { // Wait until the entire payload has been read. @@ -194,40 +195,40 @@ public class DefaultHttp2FrameReader implements Http2FrameReader { // Read the payload and fire the frame event to the observer. switch (frameType) { case DATA: - readDataFrame(payload, observer); + readDataFrame(ctx, payload, observer); break; case HEADERS: - readHeadersFrame(alloc, payload, observer); + readHeadersFrame(ctx, payload, observer); break; case PRIORITY: - readPriorityFrame(payload, observer); + readPriorityFrame(ctx, payload, observer); break; case RST_STREAM: - readRstStreamFrame(payload, observer); + readRstStreamFrame(ctx, payload, observer); break; case SETTINGS: - readSettingsFrame(payload, observer); + readSettingsFrame(ctx, payload, observer); break; case PUSH_PROMISE: - readPushPromiseFrame(alloc, payload, observer); + readPushPromiseFrame(ctx, payload, observer); break; case PING: - readPingFrame(payload, observer); + readPingFrame(ctx, payload, observer); break; case GO_AWAY: - readGoAwayFrame(payload, observer); + readGoAwayFrame(ctx, payload, observer); break; case WINDOW_UPDATE: - readWindowUpdateFrame(payload, observer); + readWindowUpdateFrame(ctx, payload, observer); break; case CONTINUATION: readContinuationFrame(payload, observer); break; case ALT_SVC: - readAltSvcFrame(payload, observer); + readAltSvcFrame(ctx, payload, observer); break; case BLOCKED: - observer.onBlockedRead(streamId); + observer.onBlockedRead(ctx, streamId); break; default: // Should never happen. @@ -390,7 +391,8 @@ public class DefaultHttp2FrameReader implements Http2FrameReader { } } - private void readDataFrame(ByteBuf payload, Http2FrameObserver observer) throws Http2Exception { + private void readDataFrame(ChannelHandlerContext ctx, ByteBuf payload, + Http2FrameObserver observer) throws Http2Exception { int dataPadding = flags.readPaddingLength(payload); // Determine how much data there is to read by removing the trailing @@ -401,12 +403,12 @@ public class DefaultHttp2FrameReader implements Http2FrameReader { } ByteBuf data = payload.readSlice(dataLength); - observer.onDataRead(streamId, data, dataPadding, flags.endOfStream(), flags.endOfSegment(), - flags.compressed()); + observer.onDataRead(ctx, streamId, data, dataPadding, flags.endOfStream(), + flags.endOfSegment(), flags.compressed()); payload.skipBytes(payload.readableBytes()); } - private void readHeadersFrame(final ByteBufAllocator alloc, ByteBuf payload, + private void readHeadersFrame(final ChannelHandlerContext ctx, ByteBuf payload, Http2FrameObserver observer) throws Http2Exception { final int headersStreamId = streamId; final Http2Flags headersFlags = flags; @@ -431,10 +433,10 @@ public class DefaultHttp2FrameReader implements Http2FrameReader { @Override public void processFragment(boolean endOfHeaders, ByteBuf fragment, int padding, Http2FrameObserver observer) throws Http2Exception { - builder().addFragment(fragment, alloc, endOfHeaders); + builder().addFragment(fragment, ctx.alloc(), endOfHeaders); if (endOfHeaders) { Http2Headers headers = builder().buildHeaders(); - observer.onHeadersRead(headersStreamId, headers, streamDependency, + observer.onHeadersRead(ctx, headersStreamId, headers, streamDependency, headersWeight, exclusive, padding, headersFlags.endOfStream(), headersFlags.endOfSegment()); close(); @@ -458,10 +460,10 @@ public class DefaultHttp2FrameReader implements Http2FrameReader { @Override public void processFragment(boolean endOfHeaders, ByteBuf fragment, int padding, Http2FrameObserver observer) throws Http2Exception { - builder().addFragment(fragment, alloc, endOfHeaders); + builder().addFragment(fragment, ctx.alloc(), endOfHeaders); if (endOfHeaders) { Http2Headers headers = builder().buildHeaders(); - observer.onHeadersRead(headersStreamId, headers, padding, + observer.onHeadersRead(ctx, headersStreamId, headers, padding, headersFlags.endOfStream(), headersFlags.endOfSegment()); close(); } @@ -473,25 +475,25 @@ public class DefaultHttp2FrameReader implements Http2FrameReader { headersContinuation.processFragment(flags.endOfHeaders(), fragment, padding, observer); } - private void readPriorityFrame(ByteBuf payload, Http2FrameObserver observer) - throws Http2Exception { + private void readPriorityFrame(ChannelHandlerContext ctx, ByteBuf payload, + Http2FrameObserver observer) throws Http2Exception { long word1 = payload.readUnsignedInt(); boolean exclusive = (word1 & 0x80000000L) > 0; int streamDependency = (int) (word1 & 0x7FFFFFFFL); short weight = payload.readUnsignedByte(); - observer.onPriorityRead(streamId, streamDependency, weight, exclusive); + observer.onPriorityRead(ctx, streamId, streamDependency, weight, exclusive); } - private void readRstStreamFrame(ByteBuf payload, Http2FrameObserver observer) - throws Http2Exception { + private void readRstStreamFrame(ChannelHandlerContext ctx, ByteBuf payload, + Http2FrameObserver observer) throws Http2Exception { long errorCode = payload.readUnsignedInt(); - observer.onRstStreamRead(streamId, errorCode); + observer.onRstStreamRead(ctx, streamId, errorCode); } - private void readSettingsFrame(ByteBuf payload, Http2FrameObserver observer) - throws Http2Exception { + private void readSettingsFrame(ChannelHandlerContext ctx, ByteBuf payload, + Http2FrameObserver observer) throws Http2Exception { if (flags.ack()) { - observer.onSettingsAckRead(); + observer.onSettingsAckRead(ctx); } else { int numSettings = payloadLength / SETTING_ENTRY_LENGTH; Http2Settings settings = new Http2Settings(); @@ -534,11 +536,11 @@ public class DefaultHttp2FrameReader implements Http2FrameReader { throw protocolError("Unsupport setting: %d", id); } } - observer.onSettingsRead(settings); + observer.onSettingsRead(ctx, settings); } } - private void readPushPromiseFrame(final ByteBufAllocator alloc, ByteBuf payload, + private void readPushPromiseFrame(final ChannelHandlerContext ctx, ByteBuf payload, Http2FrameObserver observer) throws Http2Exception { final int pushPromiseStreamId = streamId; int padding = flags.readPaddingLength(payload); @@ -554,10 +556,10 @@ public class DefaultHttp2FrameReader implements Http2FrameReader { @Override public void processFragment(boolean endOfHeaders, ByteBuf fragment, int padding, Http2FrameObserver observer) throws Http2Exception { - builder().addFragment(fragment, alloc, endOfHeaders); + builder().addFragment(fragment, ctx.alloc(), endOfHeaders); if (endOfHeaders) { Http2Headers headers = builder().buildHeaders(); - observer.onPushPromiseRead(pushPromiseStreamId, promisedStreamId, headers, + observer.onPushPromiseRead(ctx, pushPromiseStreamId, promisedStreamId, headers, padding); close(); } @@ -569,27 +571,28 @@ public class DefaultHttp2FrameReader implements Http2FrameReader { headersContinuation.processFragment(flags.endOfHeaders(), fragment, padding, observer); } - private void readPingFrame(ByteBuf payload, Http2FrameObserver observer) throws Http2Exception { + private void readPingFrame(ChannelHandlerContext ctx, ByteBuf payload, + Http2FrameObserver observer) throws Http2Exception { ByteBuf data = payload.readSlice(payload.readableBytes()); if (flags.ack()) { - observer.onPingAckRead(data); + observer.onPingAckRead(ctx, data); } else { - observer.onPingRead(data); + observer.onPingRead(ctx, data); } } - private void readGoAwayFrame(ByteBuf payload, Http2FrameObserver observer) - throws Http2Exception { + private void readGoAwayFrame(ChannelHandlerContext ctx, ByteBuf payload, + Http2FrameObserver observer) throws Http2Exception { int lastStreamId = readUnsignedInt(payload); long errorCode = payload.readUnsignedInt(); ByteBuf debugData = payload.readSlice(payload.readableBytes()); - observer.onGoAwayRead(lastStreamId, errorCode, debugData); + observer.onGoAwayRead(ctx, lastStreamId, errorCode, debugData); } - private void readWindowUpdateFrame(ByteBuf payload, Http2FrameObserver observer) - throws Http2Exception { + private void readWindowUpdateFrame(ChannelHandlerContext ctx, ByteBuf payload, + Http2FrameObserver observer) throws Http2Exception { int windowSizeIncrement = readUnsignedInt(payload); - observer.onWindowUpdateRead(streamId, windowSizeIncrement); + observer.onWindowUpdateRead(ctx, streamId, windowSizeIncrement); } private void readContinuationFrame(ByteBuf payload, Http2FrameObserver observer) @@ -602,8 +605,8 @@ public class DefaultHttp2FrameReader implements Http2FrameReader { observer); } - private void readAltSvcFrame(ByteBuf payload, Http2FrameObserver observer) - throws Http2Exception { + private void readAltSvcFrame(ChannelHandlerContext ctx, ByteBuf payload, + Http2FrameObserver observer) throws Http2Exception { long maxAge = payload.readUnsignedInt(); int port = payload.readUnsignedShort(); payload.skipBytes(1); @@ -617,7 +620,7 @@ public class DefaultHttp2FrameReader implements Http2FrameReader { origin = payload.toString(UTF_8); payload.skipBytes(payload.readableBytes()); } - observer.onAltSvcRead(streamId, maxAge, port, protocolId, host, origin); + observer.onAltSvcRead(ctx, streamId, maxAge, port, protocolId, host, origin); } /** diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/DelegatingHttp2ConnectionHandler.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/DelegatingHttp2ConnectionHandler.java index 1b03962918..99558ecc7f 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/DelegatingHttp2ConnectionHandler.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/DelegatingHttp2ConnectionHandler.java @@ -121,81 +121,83 @@ public class DelegatingHttp2ConnectionHandler extends AbstractHttp2ConnectionHan } @Override - public void onDataRead(int streamId, ByteBuf data, int padding, boolean endOfStream, - boolean endOfSegment, boolean compressed) throws Http2Exception { - observer.onDataRead(streamId, data, padding, endOfStream, endOfSegment, compressed); + public void onDataRead(ChannelHandlerContext ctx, int streamId, ByteBuf data, int padding, + boolean endOfStream, boolean endOfSegment, boolean compressed) throws Http2Exception { + observer.onDataRead(ctx, streamId, data, padding, endOfStream, endOfSegment, compressed); } @Override - public void onHeadersRead(int streamId, Http2Headers headers, int padding, boolean endStream, + public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, + int padding, boolean endStream, boolean endSegment) throws Http2Exception { + observer.onHeadersRead(ctx, streamId, headers, padding, endStream, endSegment); + } + + @Override + public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, + int streamDependency, short weight, boolean exclusive, int padding, boolean endStream, boolean endSegment) throws Http2Exception { - observer.onHeadersRead(streamId, headers, padding, endStream, endSegment); + observer.onHeadersRead(ctx, streamId, headers, streamDependency, weight, exclusive, + padding, endStream, endSegment); } @Override - public void onHeadersRead(int streamId, Http2Headers headers, int streamDependency, - short weight, boolean exclusive, int padding, boolean endStream, boolean endSegment) + public void onPriorityRead(ChannelHandlerContext ctx, int streamId, int streamDependency, + short weight, boolean exclusive) throws Http2Exception { + observer.onPriorityRead(ctx, streamId, streamDependency, weight, exclusive); + } + + @Override + public void onRstStreamRead(ChannelHandlerContext ctx, int streamId, long errorCode) throws Http2Exception { - observer.onHeadersRead(streamId, headers, streamDependency, weight, exclusive, padding, - endStream, endSegment); + observer.onRstStreamRead(ctx, streamId, errorCode); } @Override - public void onPriorityRead(int streamId, int streamDependency, short weight, boolean exclusive) + public void onSettingsAckRead(ChannelHandlerContext ctx) throws Http2Exception { + observer.onSettingsAckRead(ctx); + } + + @Override + public void onSettingsRead(ChannelHandlerContext ctx, Http2Settings settings) throws Http2Exception { + observer.onSettingsRead(ctx, settings); + } + + @Override + public void onPingRead(ChannelHandlerContext ctx, ByteBuf data) throws Http2Exception { + observer.onPingRead(ctx, data); + } + + @Override + public void onPingAckRead(ChannelHandlerContext ctx, ByteBuf data) throws Http2Exception { + observer.onPingAckRead(ctx, data); + } + + @Override + public void onPushPromiseRead(ChannelHandlerContext ctx, int streamId, int promisedStreamId, + Http2Headers headers, int padding) throws Http2Exception { + observer.onPushPromiseRead(ctx, streamId, promisedStreamId, headers, padding); + } + + @Override + public void onGoAwayRead(ChannelHandlerContext ctx, int lastStreamId, long errorCode, ByteBuf debugData) throws Http2Exception { - observer.onPriorityRead(streamId, streamDependency, weight, exclusive); + observer.onGoAwayRead(ctx, lastStreamId, errorCode, debugData); } @Override - public void onRstStreamRead(int streamId, long errorCode) throws Http2Exception { - observer.onRstStreamRead(streamId, errorCode); - } - - @Override - public void onSettingsAckRead() throws Http2Exception { - observer.onSettingsAckRead(); - } - - @Override - public void onSettingsRead(Http2Settings settings) throws Http2Exception { - observer.onSettingsRead(settings); - } - - @Override - public void onPingRead(ByteBuf data) throws Http2Exception { - observer.onPingRead(data); - } - - @Override - public void onPingAckRead(ByteBuf data) throws Http2Exception { - observer.onPingAckRead(data); - } - - @Override - public void onPushPromiseRead(int streamId, int promisedStreamId, Http2Headers headers, - int padding) throws Http2Exception { - observer.onPushPromiseRead(streamId, promisedStreamId, headers, padding); - } - - @Override - public void onGoAwayRead(int lastStreamId, long errorCode, ByteBuf debugData) + public void onWindowUpdateRead(ChannelHandlerContext ctx, int streamId, int windowSizeIncrement) throws Http2Exception { - observer.onGoAwayRead(lastStreamId, errorCode, debugData); + observer.onWindowUpdateRead(ctx, streamId, windowSizeIncrement); } @Override - public void onWindowUpdateRead(int streamId, int windowSizeIncrement) throws Http2Exception { - observer.onWindowUpdateRead(streamId, windowSizeIncrement); + public void onAltSvcRead(ChannelHandlerContext ctx, int streamId, long maxAge, int port, + ByteBuf protocolId, String host, String origin) throws Http2Exception { + observer.onAltSvcRead(ctx, streamId, maxAge, port, protocolId, host, origin); } @Override - public void onAltSvcRead(int streamId, long maxAge, int port, ByteBuf protocolId, String host, - String origin) throws Http2Exception { - observer.onAltSvcRead(streamId, maxAge, port, protocolId, host, origin); - } - - @Override - public void onBlockedRead(int streamId) throws Http2Exception { - observer.onBlockedRead(streamId); + public void onBlockedRead(ChannelHandlerContext ctx, int streamId) throws Http2Exception { + observer.onBlockedRead(ctx, streamId); } } diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2FrameObserver.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2FrameObserver.java index f05234fd04..db545889af 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2FrameObserver.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2FrameObserver.java @@ -16,6 +16,7 @@ package io.netty.handler.codec.http2; import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandlerContext; /** * An observer of HTTP/2 frames. @@ -25,20 +26,23 @@ public interface Http2FrameObserver { /** * Handles an inbound DATA frame. * + * @param ctx the context from the handler where the frame was read. * @param streamId the subject stream for the frame. - * @param data the payload of the frame. + * @param data payload buffer for the frame. If this buffer needs to be retained by the observer + * they must make a copy. * @param padding the number of padding bytes found at the end of the frame. * @param endOfStream Indicates whether this is the last frame to be sent from the remote * endpoint for this stream. * @param endOfSegment Indicates whether this frame is the end of the current segment. * @param compressed Indicates whether or not the payload is compressed with gzip encoding. */ - void onDataRead(int streamId, ByteBuf data, int padding, boolean endOfStream, - boolean endOfSegment, boolean compressed) throws Http2Exception; + void onDataRead(ChannelHandlerContext ctx, int streamId, ByteBuf data, int padding, + boolean endOfStream, boolean endOfSegment, boolean compressed) throws Http2Exception; /** * Handles an inbound HEADERS frame. * + * @param ctx the context from the handler where the frame was read. * @param streamId the subject stream for the frame. * @param headers the received headers. * @param padding the number of padding bytes found at the end of the frame. @@ -46,12 +50,13 @@ public interface Http2FrameObserver { * for this stream. * @param endSegment Indicates whether this frame is the end of the current segment. */ - void onHeadersRead(int streamId, Http2Headers headers, int padding, boolean endStream, - boolean endSegment) throws Http2Exception; + void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int padding, + boolean endStream, boolean endSegment) throws Http2Exception; /** * Handles an inbound HEADERS frame with priority information specified. * + * @param ctx the context from the handler where the frame was read. * @param streamId the subject stream for the frame. * @param headers the received headers. * @param streamDependency the stream on which this stream depends, or 0 if dependent on the @@ -63,103 +68,120 @@ public interface Http2FrameObserver { * for this stream. * @param endSegment Indicates whether this frame is the end of the current segment. */ - void onHeadersRead(int streamId, Http2Headers headers, int streamDependency, short weight, - boolean exclusive, int padding, boolean endStream, boolean endSegment) - throws Http2Exception; + void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, + int streamDependency, short weight, boolean exclusive, int padding, boolean endStream, + boolean endSegment) throws Http2Exception; /** * Handles an inbound PRIORITY frame. * + * @param ctx the context from the handler where the frame was read. * @param streamId the subject stream for the frame. * @param streamDependency the stream on which this stream depends, or 0 if dependent on the * connection. * @param weight the new weight for the stream. * @param exclusive whether or not the stream should be the exclusive dependent of its parent. */ - void onPriorityRead(int streamId, int streamDependency, short weight, boolean exclusive) - throws Http2Exception; + void onPriorityRead(ChannelHandlerContext ctx, int streamId, int streamDependency, + short weight, boolean exclusive) throws Http2Exception; /** * Handles an inbound RST_STREAM frame. * + * @param ctx the context from the handler where the frame was read. * @param streamId the stream that is terminating. * @param errorCode the error code identifying the type of failure. */ - void onRstStreamRead(int streamId, long errorCode) throws Http2Exception; + void onRstStreamRead(ChannelHandlerContext ctx, int streamId, long errorCode) throws Http2Exception; /** * Handles an inbound SETTINGS acknowledgment frame. + * @param ctx the context from the handler where the frame was read. */ - void onSettingsAckRead() throws Http2Exception; + void onSettingsAckRead(ChannelHandlerContext ctx) throws Http2Exception; /** * Handles an inbound SETTINGS frame. * + * @param ctx the context from the handler where the frame was read. * @param settings the settings received from the remote endpoint. */ - void onSettingsRead(Http2Settings settings) throws Http2Exception; + void onSettingsRead(ChannelHandlerContext ctx, Http2Settings settings) throws Http2Exception; /** * Handles an inbound PING frame. * - * @param data the payload of the frame. + * @param ctx the context from the handler where the frame was read. + * @param data the payload of the frame. If this buffer needs to be retained by the observer + * they must make a copy. */ - void onPingRead(ByteBuf data) throws Http2Exception; + void onPingRead(ChannelHandlerContext ctx, ByteBuf data) throws Http2Exception; /** * Handles an inbound PING acknowledgment. * - * @param data the payload of the frame. + * @param ctx the context from the handler where the frame was read. + * @param data the payload of the frame. If this buffer needs to be retained by the observer + * they must make a copy. */ - void onPingAckRead(ByteBuf data) throws Http2Exception; + void onPingAckRead(ChannelHandlerContext ctx, ByteBuf data) throws Http2Exception; /** * Handles an inbound PUSH_PROMISE frame. * + * @param ctx the context from the handler where the frame was read. * @param streamId the stream the frame was sent on. * @param promisedStreamId the ID of the promised stream. * @param headers the received headers. * @param paddingthe number of padding bytes found at the end of the frame. */ - void onPushPromiseRead(int streamId, int promisedStreamId, Http2Headers headers, int padding) - throws Http2Exception; + void onPushPromiseRead(ChannelHandlerContext ctx, int streamId, int promisedStreamId, + Http2Headers headers, int padding) throws Http2Exception; /** * Handles an inbound GO_AWAY frame. * + * @param ctx the context from the handler where the frame was read. * @param lastStreamId the last known stream of the remote endpoint. * @param errorCode the error code, if abnormal closure. - * @param debugData application-defined debug data. + * @param debugData application-defined debug data. If this buffer needs to be retained by the + * observer they must make a copy. */ - void onGoAwayRead(int lastStreamId, long errorCode, ByteBuf debugData) throws Http2Exception; + void onGoAwayRead(ChannelHandlerContext ctx, int lastStreamId, long errorCode, ByteBuf debugData) + throws Http2Exception; /** * Handles an inbound WINDOW_UPDATE frame. * + * @param ctx the context from the handler where the frame was read. * @param streamId the stream the frame was sent on. * @param windowSizeIncrement the increased number of bytes of the remote endpoint's flow * control window. */ - void onWindowUpdateRead(int streamId, int windowSizeIncrement) throws Http2Exception; + void onWindowUpdateRead(ChannelHandlerContext ctx, int streamId, int windowSizeIncrement) + throws Http2Exception; /** * Handles an inbound ALT_SVC frame. * + * @param ctx the context from the handler where the frame was read. * @param streamId the stream. * @param maxAge the freshness lifetime of the alternative service association. * @param port the port that the alternative service is available upon. - * @param protocolId the ALPN protocol identifier of the alternative service. + * @param protocolId the ALPN protocol identifier of the alternative service. If this buffer + * needs to be retained by the observer they must make a copy. * @param host the host that the alternative service is available upon. * @param origin an optional origin that the alternative service is available upon. May be * {@code null}. */ - void onAltSvcRead(int streamId, long maxAge, int port, ByteBuf protocolId, String host, - String origin) throws Http2Exception; + void onAltSvcRead(ChannelHandlerContext ctx, int streamId, long maxAge, int port, + ByteBuf protocolId, String host, String origin) throws Http2Exception; /** * Handles an inbound BLOCKED frame. * + * @param ctx the context from the handler where the frame was read. * @param streamId the stream that is blocked or 0 if the entire connection is blocked. */ - void onBlockedRead(int streamId) throws Http2Exception; + void onBlockedRead(ChannelHandlerContext ctx, int streamId) throws Http2Exception; } diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2FrameReader.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2FrameReader.java index 1d40401d7a..d9c306eda9 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2FrameReader.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2FrameReader.java @@ -16,7 +16,7 @@ package io.netty.handler.codec.http2; import io.netty.buffer.ByteBuf; -import io.netty.buffer.ByteBufAllocator; +import io.netty.channel.ChannelHandlerContext; import java.io.Closeable; @@ -30,7 +30,7 @@ public interface Http2FrameReader extends Closeable { * Attempts to read the next frame from the input buffer. If enough data is available to fully * read the frame, notifies the observer of the read frame. */ - void readFrame(ByteBufAllocator alloc, ByteBuf input, Http2FrameObserver observer) + void readFrame(ChannelHandlerContext ctx, ByteBuf input, Http2FrameObserver observer) throws Http2Exception; /** diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2InboundFrameLogger.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2InboundFrameLogger.java index a96febdb1c..933fd1ebc3 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2InboundFrameLogger.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2InboundFrameLogger.java @@ -17,7 +17,7 @@ package io.netty.handler.codec.http2; import static io.netty.handler.codec.http2.Http2FrameLogger.Direction.INBOUND; import io.netty.buffer.ByteBuf; -import io.netty.buffer.ByteBufAllocator; +import io.netty.channel.ChannelHandlerContext; /** * Decorator around a {@link Http2FrameReader} that logs all inbound frames before calling @@ -40,104 +40,108 @@ public class Http2InboundFrameLogger implements Http2FrameReader { } @Override - public void readFrame(ByteBufAllocator alloc, ByteBuf input, final Http2FrameObserver observer) + public void readFrame(ChannelHandlerContext ctx, ByteBuf input, final Http2FrameObserver observer) throws Http2Exception { - reader.readFrame(alloc, input, new Http2FrameObserver() { + reader.readFrame(ctx, input, new Http2FrameObserver() { @Override - public void onDataRead(int streamId, ByteBuf data, int padding, boolean endOfStream, - boolean endOfSegment, boolean compressed) throws Http2Exception { + public void onDataRead(ChannelHandlerContext ctx, int streamId, ByteBuf data, + int padding, boolean endOfStream, boolean endOfSegment, boolean compressed) + throws Http2Exception { logger.logData(INBOUND, streamId, data, padding, endOfStream, endOfSegment, compressed); - observer.onDataRead(streamId, data, padding, endOfStream, endOfSegment, compressed); + observer.onDataRead(ctx, streamId, data, padding, endOfStream, endOfSegment, compressed); } @Override - public void onHeadersRead(int streamId, Http2Headers headers, int padding, - boolean endStream, boolean endSegment) throws Http2Exception { + public void onHeadersRead(ChannelHandlerContext ctx, int streamId, + Http2Headers headers, int padding, boolean endStream, boolean endSegment) + throws Http2Exception { logger.logHeaders(INBOUND, streamId, headers, padding, endStream, endSegment); - observer.onHeadersRead(streamId, headers, padding, endStream, endSegment); + observer.onHeadersRead(ctx, streamId, headers, padding, endStream, endSegment); } @Override - public void onHeadersRead(int streamId, Http2Headers headers, int streamDependency, - short weight, boolean exclusive, int padding, boolean endStream, - boolean endSegment) throws Http2Exception { + public void onHeadersRead(ChannelHandlerContext ctx, int streamId, + Http2Headers headers, int streamDependency, short weight, boolean exclusive, + int padding, boolean endStream, boolean endSegment) throws Http2Exception { logger.logHeaders(INBOUND, streamId, headers, streamDependency, weight, exclusive, padding, endStream, endSegment); - observer.onHeadersRead(streamId, headers, streamDependency, weight, exclusive, + observer.onHeadersRead(ctx, streamId, headers, streamDependency, weight, exclusive, padding, endStream, endSegment); } @Override - public void onPriorityRead(int streamId, int streamDependency, short weight, - boolean exclusive) throws Http2Exception { + public void onPriorityRead(ChannelHandlerContext ctx, int streamId, + int streamDependency, short weight, boolean exclusive) throws Http2Exception { logger.logPriority(INBOUND, streamId, streamDependency, weight, exclusive); - observer.onPriorityRead(streamId, streamDependency, weight, exclusive); + observer.onPriorityRead(ctx, streamId, streamDependency, weight, exclusive); } @Override - public void onRstStreamRead(int streamId, long errorCode) throws Http2Exception { - logger.logRstStream(INBOUND, streamId, errorCode); - observer.onRstStreamRead(streamId, errorCode); - } - - @Override - public void onSettingsAckRead() throws Http2Exception { - logger.logSettingsAck(INBOUND); - observer.onSettingsAckRead(); - } - - @Override - public void onSettingsRead(Http2Settings settings) throws Http2Exception { - logger.logSettings(INBOUND, settings); - observer.onSettingsRead(settings); - } - - @Override - public void onPingRead(ByteBuf data) throws Http2Exception { - logger.logPing(INBOUND, data); - observer.onPingRead(data); - } - - @Override - public void onPingAckRead(ByteBuf data) throws Http2Exception { - logger.logPingAck(INBOUND, data); - observer.onPingAckRead(data); - } - - @Override - public void onPushPromiseRead(int streamId, int promisedStreamId, Http2Headers headers, - int padding) throws Http2Exception { - logger.logPushPromise(INBOUND, streamId, promisedStreamId, headers, padding); - observer.onPushPromiseRead(streamId, promisedStreamId, headers, padding); - } - - @Override - public void onGoAwayRead(int lastStreamId, long errorCode, ByteBuf debugData) + public void onRstStreamRead(ChannelHandlerContext ctx, int streamId, long errorCode) throws Http2Exception { - logger.logGoAway(INBOUND, lastStreamId, errorCode, debugData); - observer.onGoAwayRead(lastStreamId, errorCode, debugData); + logger.logRstStream(INBOUND, streamId, errorCode); + observer.onRstStreamRead(ctx, streamId, errorCode); } @Override - public void onWindowUpdateRead(int streamId, int windowSizeIncrement) + public void onSettingsAckRead(ChannelHandlerContext ctx) throws Http2Exception { + logger.logSettingsAck(INBOUND); + observer.onSettingsAckRead(ctx); + } + + @Override + public void onSettingsRead(ChannelHandlerContext ctx, Http2Settings settings) + throws Http2Exception { + logger.logSettings(INBOUND, settings); + observer.onSettingsRead(ctx, settings); + } + + @Override + public void onPingRead(ChannelHandlerContext ctx, ByteBuf data) throws Http2Exception { + logger.logPing(INBOUND, data); + observer.onPingRead(ctx, data); + } + + @Override + public void onPingAckRead(ChannelHandlerContext ctx, ByteBuf data) throws Http2Exception { + logger.logPingAck(INBOUND, data); + observer.onPingAckRead(ctx, data); + } + + @Override + public void onPushPromiseRead(ChannelHandlerContext ctx, int streamId, + int promisedStreamId, Http2Headers headers, int padding) throws Http2Exception { + logger.logPushPromise(INBOUND, streamId, promisedStreamId, headers, padding); + observer.onPushPromiseRead(ctx, streamId, promisedStreamId, headers, padding); + } + + @Override + public void onGoAwayRead(ChannelHandlerContext ctx, int lastStreamId, long errorCode, + ByteBuf debugData) throws Http2Exception { + logger.logGoAway(INBOUND, lastStreamId, errorCode, debugData); + observer.onGoAwayRead(ctx, lastStreamId, errorCode, debugData); + } + + @Override + public void onWindowUpdateRead(ChannelHandlerContext ctx, int streamId, int windowSizeIncrement) throws Http2Exception { logger.logWindowsUpdate(INBOUND, streamId, windowSizeIncrement); - observer.onWindowUpdateRead(streamId, windowSizeIncrement); + observer.onWindowUpdateRead(ctx, streamId, windowSizeIncrement); } @Override - public void onAltSvcRead(int streamId, long maxAge, int port, ByteBuf protocolId, - String host, String origin) throws Http2Exception { + public void onAltSvcRead(ChannelHandlerContext ctx, int streamId, long maxAge, + int port, ByteBuf protocolId, String host, String origin) throws Http2Exception { logger.logAltSvc(INBOUND, streamId, maxAge, port, protocolId, host, origin); - observer.onAltSvcRead(streamId, maxAge, port, protocolId, host, origin); + observer.onAltSvcRead(ctx, streamId, maxAge, port, protocolId, host, origin); } @Override - public void onBlockedRead(int streamId) throws Http2Exception { + public void onBlockedRead(ChannelHandlerContext ctx, int streamId) throws Http2Exception { logger.logBlocked(INBOUND, streamId); - observer.onBlockedRead(streamId); + observer.onBlockedRead(ctx, streamId); } }); } diff --git a/codec-http2/src/test/java/io/netty/handler/codec/http2/DefaultHttp2FrameIOTest.java b/codec-http2/src/test/java/io/netty/handler/codec/http2/DefaultHttp2FrameIOTest.java index 0399d1ad41..bd619529e0 100644 --- a/codec-http2/src/test/java/io/netty/handler/codec/http2/DefaultHttp2FrameIOTest.java +++ b/codec-http2/src/test/java/io/netty/handler/codec/http2/DefaultHttp2FrameIOTest.java @@ -71,8 +71,8 @@ public class DefaultHttp2FrameIOTest { ByteBuf data = Unpooled.EMPTY_BUFFER; writer.writeData(ctx, promise, 1000, data, 0, false, false, false); ByteBuf frame = captureWrite(); - reader.readFrame(alloc, frame, observer); - verify(observer).onDataRead(eq(1000), eq(data), eq(0), eq(false), eq(false), eq(false)); + reader.readFrame(ctx, frame, observer); + verify(observer).onDataRead(eq(ctx), eq(1000), eq(data), eq(0), eq(false), eq(false), eq(false)); } @Test @@ -80,8 +80,8 @@ public class DefaultHttp2FrameIOTest { ByteBuf data = dummyData(); writer.writeData(ctx, promise, 1000, data.retain().duplicate(), 0, false, false, false); ByteBuf frame = captureWrite(); - reader.readFrame(alloc, frame, observer); - verify(observer).onDataRead(eq(1000), eq(data), eq(0), eq(false), eq(false), eq(false)); + reader.readFrame(ctx, frame, observer); + verify(observer).onDataRead(eq(ctx), eq(1000), eq(data), eq(0), eq(false), eq(false), eq(false)); } @Test @@ -89,32 +89,32 @@ public class DefaultHttp2FrameIOTest { ByteBuf data = dummyData(); writer.writeData(ctx, promise, 1, data.retain().duplicate(), 256, true, true, true); ByteBuf frame = captureWrite(); - reader.readFrame(alloc, frame, observer); - verify(observer).onDataRead(eq(1), eq(data), eq(256), eq(true), eq(true), eq(true)); + reader.readFrame(ctx, frame, observer); + verify(observer).onDataRead(eq(ctx), eq(1), eq(data), eq(256), eq(true), eq(true), eq(true)); } @Test public void priorityShouldRoundtrip() throws Exception { writer.writePriority(ctx, promise, 1, 2, (short) 255, true); ByteBuf frame = captureWrite(); - reader.readFrame(alloc, frame, observer); - verify(observer).onPriorityRead(eq(1), eq(2), eq((short) 255), eq(true)); + reader.readFrame(ctx, frame, observer); + verify(observer).onPriorityRead(eq(ctx), eq(1), eq(2), eq((short) 255), eq(true)); } @Test public void rstStreamShouldRoundtrip() throws Exception { writer.writeRstStream(ctx, promise, 1, MAX_UNSIGNED_INT); ByteBuf frame = captureWrite(); - reader.readFrame(alloc, frame, observer); - verify(observer).onRstStreamRead(eq(1), eq(MAX_UNSIGNED_INT)); + reader.readFrame(ctx, frame, observer); + verify(observer).onRstStreamRead(eq(ctx), eq(1), eq(MAX_UNSIGNED_INT)); } @Test public void emptySettingsShouldRoundtrip() throws Exception { writer.writeSettings(ctx, promise, new Http2Settings()); ByteBuf frame = captureWrite(); - reader.readFrame(alloc, frame, observer); - verify(observer).onSettingsRead(eq(new Http2Settings())); + reader.readFrame(ctx, frame, observer); + verify(observer).onSettingsRead(eq(ctx), eq(new Http2Settings())); } @Test @@ -128,16 +128,16 @@ public class DefaultHttp2FrameIOTest { writer.writeSettings(ctx, promise, settings); ByteBuf frame = captureWrite(); - reader.readFrame(alloc, frame, observer); - verify(observer).onSettingsRead(eq(settings)); + reader.readFrame(ctx, frame, observer); + verify(observer).onSettingsRead(eq(ctx), eq(settings)); } @Test public void settingsAckShouldRoundtrip() throws Exception { writer.writeSettingsAck(ctx, promise); ByteBuf frame = captureWrite(); - reader.readFrame(alloc, frame, observer); - verify(observer).onSettingsAckRead(); + reader.readFrame(ctx, frame, observer); + verify(observer).onSettingsAckRead(eq(ctx)); } @Test @@ -145,8 +145,8 @@ public class DefaultHttp2FrameIOTest { ByteBuf data = dummyData(); writer.writePing(ctx, promise, false, data.retain().duplicate()); ByteBuf frame = captureWrite(); - reader.readFrame(alloc, frame, observer); - verify(observer).onPingRead(eq(data)); + reader.readFrame(ctx, frame, observer); + verify(observer).onPingRead(eq(ctx), eq(data)); } @Test @@ -154,8 +154,8 @@ public class DefaultHttp2FrameIOTest { ByteBuf data = dummyData(); writer.writePing(ctx, promise, true, data.retain().duplicate()); ByteBuf frame = captureWrite(); - reader.readFrame(alloc, frame, observer); - verify(observer).onPingAckRead(eq(data)); + reader.readFrame(ctx, frame, observer); + verify(observer).onPingAckRead(eq(ctx), eq(data)); } @Test @@ -163,16 +163,16 @@ public class DefaultHttp2FrameIOTest { ByteBuf data = dummyData(); writer.writeGoAway(ctx, promise, 1, MAX_UNSIGNED_INT, data.retain().duplicate()); ByteBuf frame = captureWrite(); - reader.readFrame(alloc, frame, observer); - verify(observer).onGoAwayRead(eq(1), eq(MAX_UNSIGNED_INT), eq(data)); + reader.readFrame(ctx, frame, observer); + verify(observer).onGoAwayRead(eq(ctx), eq(1), eq(MAX_UNSIGNED_INT), eq(data)); } @Test public void windowUpdateShouldRoundtrip() throws Exception { writer.writeWindowUpdate(ctx, promise, 1, Integer.MAX_VALUE); ByteBuf frame = captureWrite(); - reader.readFrame(alloc, frame, observer); - verify(observer).onWindowUpdateRead(eq(1), eq(Integer.MAX_VALUE)); + reader.readFrame(ctx, frame, observer); + verify(observer).onWindowUpdateRead(eq(ctx), eq(1), eq(Integer.MAX_VALUE)); } @Test @@ -180,8 +180,8 @@ public class DefaultHttp2FrameIOTest { writer.writeAltSvc(ctx, promise, 1, MAX_UNSIGNED_INT, MAX_UNSIGNED_SHORT, dummyData(), "host", "origin"); ByteBuf frame = captureWrite(); - reader.readFrame(alloc, frame, observer); - verify(observer).onAltSvcRead(eq(1), eq(MAX_UNSIGNED_INT), eq(MAX_UNSIGNED_SHORT), + reader.readFrame(ctx, frame, observer); + verify(observer).onAltSvcRead(eq(ctx), eq(1), eq(MAX_UNSIGNED_INT), eq(MAX_UNSIGNED_SHORT), eq(dummyData()), eq("host"), eq("origin")); } @@ -189,8 +189,8 @@ public class DefaultHttp2FrameIOTest { public void altSvcWithoutOriginShouldRoundtrip() throws Exception { writer.writeAltSvc(ctx, promise, 1, MAX_UNSIGNED_INT, MAX_UNSIGNED_SHORT, dummyData(), "host", null); ByteBuf frame = captureWrite(); - reader.readFrame(alloc, frame, observer); - verify(observer).onAltSvcRead(eq(1), eq(MAX_UNSIGNED_INT), eq(MAX_UNSIGNED_SHORT), + reader.readFrame(ctx, frame, observer); + verify(observer).onAltSvcRead(eq(ctx), eq(1), eq(MAX_UNSIGNED_INT), eq(MAX_UNSIGNED_SHORT), eq(dummyData()), eq("host"), isNull(String.class)); } @@ -198,8 +198,8 @@ public class DefaultHttp2FrameIOTest { public void blockedShouldRoundtrip() throws Exception { writer.writeBlocked(ctx, promise, 1); ByteBuf frame = captureWrite(); - reader.readFrame(alloc, frame, observer); - verify(observer).onBlockedRead(eq(1)); + reader.readFrame(ctx, frame, observer); + verify(observer).onBlockedRead(eq(ctx), eq(1)); } @Test @@ -207,8 +207,8 @@ public class DefaultHttp2FrameIOTest { Http2Headers headers = Http2Headers.EMPTY_HEADERS; writer.writeHeaders(ctx, promise, 1, headers, 0, true, true); ByteBuf frame = captureWrite(); - reader.readFrame(alloc, frame, observer); - verify(observer).onHeadersRead(eq(1), eq(headers), eq(0), eq(true), eq(true)); + reader.readFrame(ctx, frame, observer); + verify(observer).onHeadersRead(eq(ctx), eq(1), eq(headers), eq(0), eq(true), eq(true)); } @Test @@ -216,8 +216,8 @@ public class DefaultHttp2FrameIOTest { Http2Headers headers = Http2Headers.EMPTY_HEADERS; writer.writeHeaders(ctx, promise, 1, headers, 256, true, true); ByteBuf frame = captureWrite(); - reader.readFrame(alloc, frame, observer); - verify(observer).onHeadersRead(eq(1), eq(headers), eq(256), eq(true), eq(true)); + reader.readFrame(ctx, frame, observer); + verify(observer).onHeadersRead(eq(ctx), eq(1), eq(headers), eq(256), eq(true), eq(true)); } @Test @@ -225,8 +225,8 @@ public class DefaultHttp2FrameIOTest { Http2Headers headers = dummyHeaders(); writer.writeHeaders(ctx, promise, 1, headers, 0, true, true); ByteBuf frame = captureWrite(); - reader.readFrame(alloc, frame, observer); - verify(observer).onHeadersRead(eq(1), eq(headers), eq(0), eq(true), eq(true)); + reader.readFrame(ctx, frame, observer); + verify(observer).onHeadersRead(eq(ctx), eq(1), eq(headers), eq(0), eq(true), eq(true)); } @Test @@ -234,8 +234,8 @@ public class DefaultHttp2FrameIOTest { Http2Headers headers = dummyHeaders(); writer.writeHeaders(ctx, promise, 1, headers, 256, true, true); ByteBuf frame = captureWrite(); - reader.readFrame(alloc, frame, observer); - verify(observer).onHeadersRead(eq(1), eq(headers), eq(256), eq(true), eq(true)); + reader.readFrame(ctx, frame, observer); + verify(observer).onHeadersRead(eq(ctx), eq(1), eq(headers), eq(256), eq(true), eq(true)); } @Test @@ -243,8 +243,8 @@ public class DefaultHttp2FrameIOTest { Http2Headers headers = dummyHeaders(); writer.writeHeaders(ctx, promise, 1, headers, 2, (short) 3, true, 0, true, true); ByteBuf frame = captureWrite(); - reader.readFrame(alloc, frame, observer); - verify(observer).onHeadersRead(eq(1), eq(headers), eq(2), eq((short) 3), eq(true), eq(0), + reader.readFrame(ctx, frame, observer); + verify(observer).onHeadersRead(eq(ctx), eq(1), eq(headers), eq(2), eq((short) 3), eq(true), eq(0), eq(true), eq(true)); } @@ -253,8 +253,8 @@ public class DefaultHttp2FrameIOTest { Http2Headers headers = dummyHeaders(); writer.writeHeaders(ctx, promise, 1, headers, 2, (short) 3, true, 256, true, true); ByteBuf frame = captureWrite(); - reader.readFrame(alloc, frame, observer); - verify(observer).onHeadersRead(eq(1), eq(headers), eq(2), eq((short) 3), eq(true), eq(256), + reader.readFrame(ctx, frame, observer); + verify(observer).onHeadersRead(eq(ctx), eq(1), eq(headers), eq(2), eq((short) 3), eq(true), eq(256), eq(true), eq(true)); } @@ -263,8 +263,8 @@ public class DefaultHttp2FrameIOTest { Http2Headers headers = largeHeaders(); writer.writeHeaders(ctx, promise, 1, headers, 2, (short) 3, true, 0, true, true); ByteBuf frame = captureWrite(); - reader.readFrame(alloc, frame, observer); - verify(observer).onHeadersRead(eq(1), eq(headers), eq(2), eq((short) 3), eq(true), eq(0), + reader.readFrame(ctx, frame, observer); + verify(observer).onHeadersRead(eq(ctx), eq(1), eq(headers), eq(2), eq((short) 3), eq(true), eq(0), eq(true), eq(true)); } @@ -273,8 +273,8 @@ public class DefaultHttp2FrameIOTest { Http2Headers headers = largeHeaders(); writer.writeHeaders(ctx, promise, 1, headers, 2, (short) 3, true, 256, true, true); ByteBuf frame = captureWrite(); - reader.readFrame(alloc, frame, observer); - verify(observer).onHeadersRead(eq(1), eq(headers), eq(2), eq((short) 3), eq(true), eq(256), + reader.readFrame(ctx, frame, observer); + verify(observer).onHeadersRead(eq(ctx), eq(1), eq(headers), eq(2), eq((short) 3), eq(true), eq(256), eq(true), eq(true)); } @@ -283,8 +283,8 @@ public class DefaultHttp2FrameIOTest { Http2Headers headers = Http2Headers.EMPTY_HEADERS; writer.writePushPromise(ctx, promise, 1, 2, headers, 0); ByteBuf frame = captureWrite(); - reader.readFrame(alloc, frame, observer); - verify(observer).onPushPromiseRead(eq(1), eq(2), eq(headers), eq(0)); + reader.readFrame(ctx, frame, observer); + verify(observer).onPushPromiseRead(eq(ctx), eq(1), eq(2), eq(headers), eq(0)); } @Test @@ -292,8 +292,8 @@ public class DefaultHttp2FrameIOTest { Http2Headers headers = dummyHeaders(); writer.writePushPromise(ctx, promise, 1, 2, headers, 0); ByteBuf frame = captureWrite(); - reader.readFrame(alloc, frame, observer); - verify(observer).onPushPromiseRead(eq(1), eq(2), eq(headers), eq(0)); + reader.readFrame(ctx, frame, observer); + verify(observer).onPushPromiseRead(eq(ctx), eq(1), eq(2), eq(headers), eq(0)); } @Test @@ -301,8 +301,8 @@ public class DefaultHttp2FrameIOTest { Http2Headers headers = dummyHeaders(); writer.writePushPromise(ctx, promise, 1, 2, headers, 256); ByteBuf frame = captureWrite(); - reader.readFrame(alloc, frame, observer); - verify(observer).onPushPromiseRead(eq(1), eq(2), eq(headers), eq(256)); + reader.readFrame(ctx, frame, observer); + verify(observer).onPushPromiseRead(eq(ctx), eq(1), eq(2), eq(headers), eq(256)); } @Test @@ -310,8 +310,8 @@ public class DefaultHttp2FrameIOTest { Http2Headers headers = largeHeaders(); writer.writePushPromise(ctx, promise, 1, 2, headers, 0); ByteBuf frame = captureWrite(); - reader.readFrame(alloc, frame, observer); - verify(observer).onPushPromiseRead(eq(1), eq(2), eq(headers), eq(0)); + reader.readFrame(ctx, frame, observer); + verify(observer).onPushPromiseRead(eq(ctx), eq(1), eq(2), eq(headers), eq(0)); } @Test @@ -319,8 +319,8 @@ public class DefaultHttp2FrameIOTest { Http2Headers headers = largeHeaders(); writer.writePushPromise(ctx, promise, 1, 2, headers, 256); ByteBuf frame = captureWrite(); - reader.readFrame(alloc, frame, observer); - verify(observer).onPushPromiseRead(eq(1), eq(2), eq(headers), eq(256)); + reader.readFrame(ctx, frame, observer); + verify(observer).onPushPromiseRead(eq(ctx), eq(1), eq(2), eq(headers), eq(256)); } private ByteBuf captureWrite() { diff --git a/codec-http2/src/test/java/io/netty/handler/codec/http2/DelegatingHttp2ConnectionHandlerTest.java b/codec-http2/src/test/java/io/netty/handler/codec/http2/DelegatingHttp2ConnectionHandlerTest.java index 9f967e8ca6..a6549eedfb 100644 --- a/codec-http2/src/test/java/io/netty/handler/codec/http2/DelegatingHttp2ConnectionHandlerTest.java +++ b/codec-http2/src/test/java/io/netty/handler/codec/http2/DelegatingHttp2ConnectionHandlerTest.java @@ -39,7 +39,6 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import io.netty.buffer.ByteBuf; -import io.netty.buffer.ByteBufAllocator; import io.netty.buffer.Unpooled; import io.netty.channel.Channel; import io.netty.channel.ChannelFuture; @@ -150,8 +149,8 @@ public class DelegatingHttp2ConnectionHandlerTest { verify(writer).writeSettings(eq(ctx), eq(promise), eq(settings)); // Simulate receiving the initial settings from the remote endpoint. - decode().onSettingsRead(new Http2Settings()); - verify(observer).onSettingsRead(new Http2Settings()); + decode().onSettingsRead(ctx, new Http2Settings()); + verify(observer).onSettingsRead(eq(ctx), eq(new Http2Settings())); verify(writer).writeSettingsAck(eq(ctx), eq(promise)); // Re-mock the context so no calls are registered. @@ -198,123 +197,123 @@ public class DelegatingHttp2ConnectionHandlerTest { @Test public void dataReadAfterGoAwayShouldApplyFlowControl() throws Exception { when(connection.isGoAwaySent()).thenReturn(true); - decode().onDataRead(STREAM_ID, dummyData(), 10, true, true, true); + decode().onDataRead(ctx, STREAM_ID, dummyData(), 10, true, true, true); verify(inboundFlow).applyInboundFlowControl(eq(STREAM_ID), eq(dummyData()), eq(10), eq(true), eq(true), eq(true), any(Http2InboundFlowController.FrameWriter.class)); // Verify that the event was absorbed and not propagated to the oberver. - verify(observer, never()).onDataRead(anyInt(), any(ByteBuf.class), anyInt(), anyBoolean(), + verify(observer, never()).onDataRead(eq(ctx), anyInt(), any(ByteBuf.class), anyInt(), anyBoolean(), anyBoolean(), anyBoolean()); } @Test public void dataReadWithEndOfStreamShouldCloseRemoteSide() throws Exception { - decode().onDataRead(STREAM_ID, dummyData(), 10, true, false, false); + decode().onDataRead(ctx, STREAM_ID, dummyData(), 10, true, false, false); verify(inboundFlow).applyInboundFlowControl(eq(STREAM_ID), eq(dummyData()), eq(10), eq(true), eq(false), eq(false), any(Http2InboundFlowController.FrameWriter.class)); verify(stream).closeRemoteSide(); - verify(observer).onDataRead(eq(STREAM_ID), eq(dummyData()), eq(10), eq(true), eq(false), - eq(false)); + verify(observer).onDataRead(eq(ctx), eq(STREAM_ID), eq(dummyData()), eq(10), eq(true), + eq(false), eq(false)); } @Test public void dataReadWithShouldAllowCompression() throws Exception { when(local.allowCompressedData()).thenReturn(true); - decode().onDataRead(STREAM_ID, dummyData(), 10, false, false, true); + decode().onDataRead(ctx, STREAM_ID, dummyData(), 10, false, false, true); verify(inboundFlow).applyInboundFlowControl(eq(STREAM_ID), eq(dummyData()), eq(10), eq(false), eq(false), eq(true), any(Http2InboundFlowController.FrameWriter.class)); verify(stream, never()).closeRemoteSide(); - verify(observer).onDataRead(eq(STREAM_ID), eq(dummyData()), eq(10), eq(false), eq(false), - eq(true)); + verify(observer).onDataRead(eq(ctx), eq(STREAM_ID), eq(dummyData()), eq(10), eq(false), + eq(false), eq(true)); } @Test(expected = Http2Exception.class) public void dataReadShouldDisallowCompression() throws Exception { when(local.allowCompressedData()).thenReturn(false); - decode().onDataRead(STREAM_ID, dummyData(), 10, false, false, true); + decode().onDataRead(ctx, STREAM_ID, dummyData(), 10, false, false, true); } @Test public void headersReadAfterGoAwayShouldBeIgnored() throws Exception { when(connection.isGoAwaySent()).thenReturn(true); - decode().onHeadersRead(STREAM_ID, EMPTY_HEADERS, 0, false, false); + decode().onHeadersRead(ctx, STREAM_ID, EMPTY_HEADERS, 0, false, false); verify(remote, never()).createStream(eq(STREAM_ID), eq(false)); // Verify that the event was absorbed and not propagated to the oberver. - verify(observer, never()).onHeadersRead(anyInt(), any(Http2Headers.class), anyInt(), - anyBoolean(), anyBoolean()); + verify(observer, never()).onHeadersRead(eq(ctx), anyInt(), any(Http2Headers.class), + anyInt(), anyBoolean(), anyBoolean()); verify(outboundFlow, never()).updateStream(anyInt(), anyInt(), anyShort(), anyBoolean()); verify(inboundFlow, never()).addStream(anyInt()); } @Test public void headersReadForUnknownStreamShouldCreateStream() throws Exception { - decode().onHeadersRead(5, EMPTY_HEADERS, 0, false, false); + decode().onHeadersRead(ctx, 5, EMPTY_HEADERS, 0, false, false); verify(remote).createStream(eq(5), eq(false)); verify(outboundFlow).addStream(eq(5), eq(0), eq(DEFAULT_PRIORITY_WEIGHT), eq(false)); verify(inboundFlow).addStream(5); - verify(observer).onHeadersRead(eq(5), eq(EMPTY_HEADERS), eq(0), + verify(observer).onHeadersRead(eq(ctx), eq(5), eq(EMPTY_HEADERS), eq(0), eq(DEFAULT_PRIORITY_WEIGHT), eq(false), eq(0), eq(false), eq(false)); } @Test public void headersReadForUnknownStreamShouldCreateHalfClosedStream() throws Exception { - decode().onHeadersRead(5, EMPTY_HEADERS, 0, true, false); + decode().onHeadersRead(ctx, 5, EMPTY_HEADERS, 0, true, false); verify(remote).createStream(eq(5), eq(true)); verify(outboundFlow).addStream(eq(5), eq(0), eq(DEFAULT_PRIORITY_WEIGHT), eq(false)); verify(inboundFlow, never()).addStream(5); - verify(observer).onHeadersRead(eq(5), eq(EMPTY_HEADERS), eq(0), + verify(observer).onHeadersRead(eq(ctx), eq(5), eq(EMPTY_HEADERS), eq(0), eq(DEFAULT_PRIORITY_WEIGHT), eq(false), eq(0), eq(true), eq(false)); } @Test public void headersReadForPromisedStreamShouldHalfOpenStream() throws Exception { when(stream.state()).thenReturn(RESERVED_REMOTE); - decode().onHeadersRead(STREAM_ID, EMPTY_HEADERS, 0, false, false); + decode().onHeadersRead(ctx, STREAM_ID, EMPTY_HEADERS, 0, false, false); verify(stream).openForPush(); verify(outboundFlow, never()).addStream(anyInt(), anyInt(), anyShort(), anyBoolean()); verify(inboundFlow).addStream(STREAM_ID); - verify(observer).onHeadersRead(eq(STREAM_ID), eq(EMPTY_HEADERS), eq(0), + verify(observer).onHeadersRead(eq(ctx), eq(STREAM_ID), eq(EMPTY_HEADERS), eq(0), eq(DEFAULT_PRIORITY_WEIGHT), eq(false), eq(0), eq(false), eq(false)); } @Test public void headersReadForPromisedStreamShouldCloseStream() throws Exception { when(stream.state()).thenReturn(RESERVED_REMOTE); - decode().onHeadersRead(STREAM_ID, EMPTY_HEADERS, 0, true, false); + decode().onHeadersRead(ctx, STREAM_ID, EMPTY_HEADERS, 0, true, false); verify(stream).openForPush(); verify(stream).close(); verify(outboundFlow, never()).addStream(anyInt(), anyInt(), anyShort(), anyBoolean()); verify(inboundFlow, never()).addStream(STREAM_ID); verify(outboundFlow).removeStream(STREAM_ID); verify(inboundFlow).removeStream(STREAM_ID); - verify(observer).onHeadersRead(eq(STREAM_ID), eq(EMPTY_HEADERS), eq(0), + verify(observer).onHeadersRead(eq(ctx), eq(STREAM_ID), eq(EMPTY_HEADERS), eq(0), eq(DEFAULT_PRIORITY_WEIGHT), eq(false), eq(0), eq(true), eq(false)); } @Test public void pushPromiseReadAfterGoAwayShouldBeIgnored() throws Exception { when(connection.isGoAwaySent()).thenReturn(true); - decode().onPushPromiseRead(STREAM_ID, PUSH_STREAM_ID, EMPTY_HEADERS, 0); + decode().onPushPromiseRead(ctx, STREAM_ID, PUSH_STREAM_ID, EMPTY_HEADERS, 0); verify(remote, never()).reservePushStream(anyInt(), any(Http2Stream.class)); - verify(observer, never()).onPushPromiseRead(anyInt(), anyInt(), any(Http2Headers.class), - anyInt()); + verify(observer, never()).onPushPromiseRead(eq(ctx), anyInt(), anyInt(), + any(Http2Headers.class), anyInt()); } @Test public void pushPromiseReadShouldSucceed() throws Exception { - decode().onPushPromiseRead(STREAM_ID, PUSH_STREAM_ID, EMPTY_HEADERS, 0); + decode().onPushPromiseRead(ctx, STREAM_ID, PUSH_STREAM_ID, EMPTY_HEADERS, 0); verify(remote).reservePushStream(eq(PUSH_STREAM_ID), eq(stream)); - verify(observer).onPushPromiseRead(eq(STREAM_ID), eq(PUSH_STREAM_ID), eq(EMPTY_HEADERS), - eq(0)); + verify(observer).onPushPromiseRead(eq(ctx), eq(STREAM_ID), eq(PUSH_STREAM_ID), + eq(EMPTY_HEADERS), eq(0)); } @Test public void priorityReadAfterGoAwayShouldBeIgnored() throws Exception { when(connection.isGoAwaySent()).thenReturn(true); - decode().onPriorityRead(STREAM_ID, 0, (short) 255, true); + decode().onPriorityRead(ctx, STREAM_ID, 0, (short) 255, true); verify(outboundFlow, never()).updateStream(anyInt(), anyInt(), anyShort(), anyBoolean()); - verify(observer, never()).onPriorityRead(anyInt(), anyInt(), anyShort(), anyBoolean()); + verify(observer, never()).onPriorityRead(eq(ctx), anyInt(), anyInt(), anyShort(), anyBoolean()); } @Test @@ -322,79 +321,79 @@ public class DelegatingHttp2ConnectionHandlerTest { // The outbound flow controller may keep a prioritized stream around for some time after // being closed. Verify that the flow controller is updated regardless of the presence of // the stream. - decode().onPriorityRead(5, 0, (short) 255, true); + decode().onPriorityRead(ctx, 5, 0, (short) 255, true); verify(outboundFlow).updateStream(eq(5), eq(0), eq((short) 255), eq(true)); - verify(observer).onPriorityRead(eq(5), eq(0), eq((short) 255), eq(true)); + verify(observer).onPriorityRead(eq(ctx), eq(5), eq(0), eq((short) 255), eq(true)); } @Test public void priorityReadShouldSucceed() throws Exception { - decode().onPriorityRead(STREAM_ID, 0, (short) 255, true); + decode().onPriorityRead(ctx, STREAM_ID, 0, (short) 255, true); verify(outboundFlow).updateStream(eq(STREAM_ID), eq(0), eq((short) 255), eq(true)); - verify(observer).onPriorityRead(eq(STREAM_ID), eq(0), eq((short) 255), eq(true)); + verify(observer).onPriorityRead(eq(ctx), eq(STREAM_ID), eq(0), eq((short) 255), eq(true)); } @Test public void windowUpdateReadAfterGoAwayShouldBeIgnored() throws Exception { when(connection.isGoAwaySent()).thenReturn(true); - decode().onWindowUpdateRead(STREAM_ID, 10); + decode().onWindowUpdateRead(ctx, STREAM_ID, 10); verify(outboundFlow, never()).updateOutboundWindowSize(anyInt(), anyInt()); - verify(observer, never()).onWindowUpdateRead(anyInt(), anyInt()); + verify(observer, never()).onWindowUpdateRead(eq(ctx), anyInt(), anyInt()); } @Test public void windowUpdateReadForUnknownStreamShouldBeIgnored() throws Exception { - decode().onWindowUpdateRead(5, 10); + decode().onWindowUpdateRead(ctx, 5, 10); verify(outboundFlow, never()).updateOutboundWindowSize(anyInt(), anyInt()); - verify(observer, never()).onWindowUpdateRead(anyInt(), anyInt()); + verify(observer, never()).onWindowUpdateRead(eq(ctx), anyInt(), anyInt()); } @Test public void windowUpdateReadShouldSucceed() throws Exception { - decode().onWindowUpdateRead(STREAM_ID, 10); + decode().onWindowUpdateRead(ctx, STREAM_ID, 10); verify(outboundFlow).updateOutboundWindowSize(eq(STREAM_ID), eq(10)); - verify(observer).onWindowUpdateRead(eq(STREAM_ID), eq(10)); + verify(observer).onWindowUpdateRead(eq(ctx), eq(STREAM_ID), eq(10)); } @Test public void rstStreamReadAfterGoAwayShouldBeIgnored() throws Exception { when(connection.isGoAwaySent()).thenReturn(true); - decode().onRstStreamRead(STREAM_ID, PROTOCOL_ERROR.code()); + decode().onRstStreamRead(ctx, STREAM_ID, PROTOCOL_ERROR.code()); verify(stream, never()).close(); - verify(observer, never()).onRstStreamRead(anyInt(), anyLong()); + verify(observer, never()).onRstStreamRead(eq(ctx), anyInt(), anyLong()); } @Test public void rstStreamReadForUnknownStreamShouldBeIgnored() throws Exception { - decode().onRstStreamRead(5, PROTOCOL_ERROR.code()); + decode().onRstStreamRead(ctx, 5, PROTOCOL_ERROR.code()); verify(stream, never()).close(); - verify(observer, never()).onRstStreamRead(anyInt(), anyLong()); + verify(observer, never()).onRstStreamRead(eq(ctx), anyInt(), anyLong()); } @Test public void rstStreamReadShouldCloseStream() throws Exception { - decode().onRstStreamRead(STREAM_ID, PROTOCOL_ERROR.code()); + decode().onRstStreamRead(ctx, STREAM_ID, PROTOCOL_ERROR.code()); verify(stream).close(); - verify(observer).onRstStreamRead(eq(STREAM_ID), eq((long) PROTOCOL_ERROR.code())); + verify(observer).onRstStreamRead(eq(ctx), eq(STREAM_ID), eq((long) PROTOCOL_ERROR.code())); } @Test public void pingReadWithAckShouldNotifyObserver() throws Exception { - decode().onPingAckRead(emptyPingBuf()); - verify(observer).onPingAckRead(eq(emptyPingBuf())); + decode().onPingAckRead(ctx, emptyPingBuf()); + verify(observer).onPingAckRead(eq(ctx), eq(emptyPingBuf())); } @Test public void pingReadShouldReplyWithAck() throws Exception { - decode().onPingRead(emptyPingBuf()); + decode().onPingRead(ctx, emptyPingBuf()); verify(writer).writePing(eq(ctx), eq(promise), eq(true), eq(emptyPingBuf())); - verify(observer, never()).onPingAckRead(any(ByteBuf.class)); + verify(observer, never()).onPingAckRead(eq(ctx), any(ByteBuf.class)); } @Test public void settingsReadWithAckShouldNotifyObserver() throws Exception { - decode().onSettingsAckRead(); - verify(observer).onSettingsAckRead(); + decode().onSettingsAckRead(ctx); + verify(observer).onSettingsAckRead(eq(ctx)); } @Test @@ -405,7 +404,7 @@ public class DelegatingHttp2ConnectionHandlerTest { settings.maxConcurrentStreams(456); settings.allowCompressedData(true); settings.maxHeaderTableSize(789); - decode().onSettingsRead(settings); + decode().onSettingsRead(ctx, settings); verify(remote).allowPushTo(true); verify(outboundFlow).initialOutboundWindowSize(123); verify(local).maxStreams(456); @@ -413,14 +412,14 @@ public class DelegatingHttp2ConnectionHandlerTest { verify(writer).maxHeaderTableSize(789); // Take into account the time this was called during setup(). verify(writer, times(2)).writeSettingsAck(eq(ctx), eq(promise)); - verify(observer).onSettingsRead(eq(settings)); + verify(observer).onSettingsRead(eq(ctx), eq(settings)); } @Test public void goAwayShoultShouldUpdateConnectionState() throws Exception { - decode().onGoAwayRead(1, 2, EMPTY_BUFFER); + decode().onGoAwayRead(ctx, 1, 2, EMPTY_BUFFER); verify(connection).goAwayReceived(); - verify(observer).onGoAwayRead(eq(1), eq(2L), eq(EMPTY_BUFFER)); + verify(observer).onGoAwayRead(eq(ctx), eq(1), eq(2L), eq(EMPTY_BUFFER)); } @Test(expected = Http2Exception.class) @@ -595,8 +594,7 @@ public class DelegatingHttp2ConnectionHandlerTest { private Http2FrameObserver decode() throws Exception { ArgumentCaptor internalObserver = ArgumentCaptor.forClass(Http2FrameObserver.class); - doNothing().when(reader).readFrame(any(ByteBufAllocator.class), any(ByteBuf.class), - internalObserver.capture()); + doNothing().when(reader).readFrame(eq(ctx), any(ByteBuf.class), internalObserver.capture()); handler.decode(ctx, EMPTY_BUFFER, Collections.emptyList()); return internalObserver.getValue(); } diff --git a/codec-http2/src/test/java/io/netty/handler/codec/http2/Http2ConnectionRoundtripTest.java b/codec-http2/src/test/java/io/netty/handler/codec/http2/Http2ConnectionRoundtripTest.java index 962a223f98..21b0418ebd 100644 --- a/codec-http2/src/test/java/io/netty/handler/codec/http2/Http2ConnectionRoundtripTest.java +++ b/codec-http2/src/test/java/io/netty/handler/codec/http2/Http2ConnectionRoundtripTest.java @@ -17,6 +17,7 @@ package io.netty.handler.codec.http2; import static java.util.concurrent.TimeUnit.SECONDS; import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyInt; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.times; @@ -128,10 +129,11 @@ public class Http2ConnectionRoundtripTest { // Wait for all frames to be received. awaitRequests(); - verify(serverObserver, times(numStreams)).onHeadersRead(anyInt(), eq(headers), eq(0), - eq((short) 16), eq(false), eq(0), eq(false), eq(false)); - verify(serverObserver, times(numStreams)).onDataRead(anyInt(), - eq(Unpooled.copiedBuffer(text.getBytes())), eq(0), eq(true), eq(true), eq(false)); + verify(serverObserver, times(numStreams)).onHeadersRead(any(ChannelHandlerContext.class), + anyInt(), eq(headers), eq(0), eq((short) 16), eq(false), eq(0), eq(false), + eq(false)); + verify(serverObserver, times(numStreams)).onDataRead(any(ChannelHandlerContext.class), + anyInt(), eq(Unpooled.copiedBuffer(text.getBytes())), eq(0), eq(true), eq(true), eq(false)); } private void awaitRequests() throws Exception { @@ -157,97 +159,100 @@ public class Http2ConnectionRoundtripTest { private final class FrameCountDown implements Http2FrameObserver { @Override - public void onDataRead(int streamId, ByteBuf data, int padding, boolean endOfStream, - boolean endOfSegment, boolean compressed) throws Http2Exception { - serverObserver.onDataRead(streamId, copy(data), padding, endOfStream, endOfSegment, - compressed); - requestLatch.countDown(); - } - - @Override - public void onHeadersRead(int streamId, Http2Headers headers, int padding, - boolean endStream, boolean endSegment) throws Http2Exception { - serverObserver.onHeadersRead(streamId, headers, padding, endStream, endSegment); - requestLatch.countDown(); - } - - @Override - public void - onHeadersRead(int streamId, Http2Headers headers, int streamDependency, - short weight, boolean exclusive, int padding, boolean endStream, - boolean endSegment) throws Http2Exception { - serverObserver.onHeadersRead(streamId, headers, streamDependency, weight, exclusive, - padding, endStream, endSegment); - requestLatch.countDown(); - } - - @Override - public void onPriorityRead(int streamId, int streamDependency, short weight, - boolean exclusive) throws Http2Exception { - serverObserver.onPriorityRead(streamId, streamDependency, weight, exclusive); - requestLatch.countDown(); - } - - @Override - public void onRstStreamRead(int streamId, long errorCode) throws Http2Exception { - serverObserver.onRstStreamRead(streamId, errorCode); - requestLatch.countDown(); - } - - @Override - public void onSettingsAckRead() throws Http2Exception { - serverObserver.onSettingsAckRead(); - requestLatch.countDown(); - } - - @Override - public void onSettingsRead(Http2Settings settings) throws Http2Exception { - serverObserver.onSettingsRead(settings); - requestLatch.countDown(); - } - - @Override - public void onPingRead(ByteBuf data) throws Http2Exception { - serverObserver.onPingRead(copy(data)); - requestLatch.countDown(); - } - - @Override - public void onPingAckRead(ByteBuf data) throws Http2Exception { - serverObserver.onPingAckRead(copy(data)); - requestLatch.countDown(); - } - - @Override - public void onPushPromiseRead(int streamId, int promisedStreamId, Http2Headers headers, - int padding) throws Http2Exception { - serverObserver.onPushPromiseRead(streamId, promisedStreamId, headers, padding); - requestLatch.countDown(); - } - - @Override - public void onGoAwayRead(int lastStreamId, long errorCode, ByteBuf debugData) + public void onDataRead(ChannelHandlerContext ctx, int streamId, ByteBuf data, int padding, + boolean endOfStream, boolean endOfSegment, boolean compressed) throws Http2Exception { - serverObserver.onGoAwayRead(lastStreamId, errorCode, copy(debugData)); + serverObserver.onDataRead(ctx, streamId, copy(data), padding, endOfStream, + endOfSegment, compressed); requestLatch.countDown(); } @Override - public void onWindowUpdateRead(int streamId, int windowSizeIncrement) throws Http2Exception { - serverObserver.onWindowUpdateRead(streamId, windowSizeIncrement); + public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, + int padding, boolean endStream, boolean endSegment) throws Http2Exception { + serverObserver.onHeadersRead(ctx, streamId, headers, padding, endStream, endSegment); requestLatch.countDown(); } @Override - public void onAltSvcRead(int streamId, long maxAge, int port, ByteBuf protocolId, - String host, String origin) throws Http2Exception { - serverObserver.onAltSvcRead(streamId, maxAge, port, copy(protocolId), host, origin); + public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, + int streamDependency, short weight, boolean exclusive, int padding, + boolean endStream, boolean endSegment) throws Http2Exception { + serverObserver.onHeadersRead(ctx, streamId, headers, streamDependency, weight, + exclusive, padding, endStream, endSegment); requestLatch.countDown(); } @Override - public void onBlockedRead(int streamId) throws Http2Exception { - serverObserver.onBlockedRead(streamId); + public void onPriorityRead(ChannelHandlerContext ctx, int streamId, int streamDependency, + short weight, boolean exclusive) throws Http2Exception { + serverObserver.onPriorityRead(ctx, streamId, streamDependency, weight, exclusive); + requestLatch.countDown(); + } + + @Override + public void onRstStreamRead(ChannelHandlerContext ctx, int streamId, long errorCode) + throws Http2Exception { + serverObserver.onRstStreamRead(ctx, streamId, errorCode); + requestLatch.countDown(); + } + + @Override + public void onSettingsAckRead(ChannelHandlerContext ctx) throws Http2Exception { + serverObserver.onSettingsAckRead(ctx); + requestLatch.countDown(); + } + + @Override + public void onSettingsRead(ChannelHandlerContext ctx, Http2Settings settings) throws Http2Exception { + serverObserver.onSettingsRead(ctx, settings); + requestLatch.countDown(); + } + + @Override + public void onPingRead(ChannelHandlerContext ctx, ByteBuf data) throws Http2Exception { + serverObserver.onPingRead(ctx, copy(data)); + requestLatch.countDown(); + } + + @Override + public void onPingAckRead(ChannelHandlerContext ctx, ByteBuf data) throws Http2Exception { + serverObserver.onPingAckRead(ctx, copy(data)); + requestLatch.countDown(); + } + + @Override + public void onPushPromiseRead(ChannelHandlerContext ctx, int streamId, + int promisedStreamId, Http2Headers headers, int padding) throws Http2Exception { + serverObserver.onPushPromiseRead(ctx, streamId, promisedStreamId, headers, padding); + requestLatch.countDown(); + } + + @Override + public void onGoAwayRead(ChannelHandlerContext ctx, int lastStreamId, long errorCode, ByteBuf debugData) + throws Http2Exception { + serverObserver.onGoAwayRead(ctx, lastStreamId, errorCode, copy(debugData)); + requestLatch.countDown(); + } + + @Override + public void onWindowUpdateRead(ChannelHandlerContext ctx, int streamId, + int windowSizeIncrement) throws Http2Exception { + serverObserver.onWindowUpdateRead(ctx, streamId, windowSizeIncrement); + requestLatch.countDown(); + } + + @Override + public void onAltSvcRead(ChannelHandlerContext ctx, int streamId, long maxAge, int port, + ByteBuf protocolId, String host, String origin) throws Http2Exception { + serverObserver + .onAltSvcRead(ctx, streamId, maxAge, port, copy(protocolId), host, origin); + requestLatch.countDown(); + } + + @Override + public void onBlockedRead(ChannelHandlerContext ctx, int streamId) throws Http2Exception { + serverObserver.onBlockedRead(ctx, streamId); requestLatch.countDown(); } diff --git a/codec-http2/src/test/java/io/netty/handler/codec/http2/Http2FrameRoundtripTest.java b/codec-http2/src/test/java/io/netty/handler/codec/http2/Http2FrameRoundtripTest.java index c99fe441ce..e5df13c08c 100644 --- a/codec-http2/src/test/java/io/netty/handler/codec/http2/Http2FrameRoundtripTest.java +++ b/codec-http2/src/test/java/io/netty/handler/codec/http2/Http2FrameRoundtripTest.java @@ -18,6 +18,7 @@ package io.netty.handler.codec.http2; import static io.netty.util.CharsetUtil.UTF_8; import static java.util.concurrent.TimeUnit.SECONDS; import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.any; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.verify; import io.netty.bootstrap.Bootstrap; @@ -117,8 +118,8 @@ public class Http2FrameRoundtripTest { Unpooled.copiedBuffer(text.getBytes()), 100, true, false, false); awaitRequests(); - verify(serverObserver).onDataRead(eq(0x7FFFFFFF), dataCaptor.capture(), eq(100), eq(true), - eq(false), eq(false)); + verify(serverObserver).onDataRead(any(ChannelHandlerContext.class), eq(0x7FFFFFFF), + dataCaptor.capture(), eq(100), eq(true), eq(false), eq(false)); } @Test @@ -129,8 +130,8 @@ public class Http2FrameRoundtripTest { frameWriter.writeHeaders(ctx(), newPromise(), 0x7FFFFFFF, headers, 0, true, false); awaitRequests(); - verify(serverObserver).onHeadersRead(eq(0x7FFFFFFF), eq(headers), eq(0), eq(true), - eq(false)); + verify(serverObserver).onHeadersRead(any(ChannelHandlerContext.class), eq(0x7FFFFFFF), + eq(headers), eq(0), eq(true), eq(false)); } @Test @@ -142,8 +143,8 @@ public class Http2FrameRoundtripTest { true, false); awaitRequests(); - verify(serverObserver).onHeadersRead(eq(0x7FFFFFFF), eq(headers), eq(4), eq((short) 255), - eq(true), eq(0), eq(true), eq(false)); + verify(serverObserver).onHeadersRead(any(ChannelHandlerContext.class), eq(0x7FFFFFFF), + eq(headers), eq(4), eq((short) 255), eq(true), eq(0), eq(true), eq(false)); } @Test @@ -153,7 +154,8 @@ public class Http2FrameRoundtripTest { Unpooled.copiedBuffer(text.getBytes())); awaitRequests(); - verify(serverObserver).onGoAwayRead(eq(0x7FFFFFFF), eq(0xFFFFFFFFL), dataCaptor.capture()); + verify(serverObserver).onGoAwayRead(any(ChannelHandlerContext.class), eq(0x7FFFFFFF), + eq(0xFFFFFFFFL), dataCaptor.capture()); } @Test @@ -162,7 +164,7 @@ public class Http2FrameRoundtripTest { frameWriter.writePing(ctx(), ctx().newPromise(), true, buf); awaitRequests(); - verify(serverObserver).onPingAckRead(dataCaptor.capture()); + verify(serverObserver).onPingAckRead(any(ChannelHandlerContext.class), dataCaptor.capture()); } @Test @@ -170,7 +172,8 @@ public class Http2FrameRoundtripTest { frameWriter.writePriority(ctx(), newPromise(), 0x7FFFFFFF, 1, (short) 1, true); awaitRequests(); - verify(serverObserver).onPriorityRead(eq(0x7FFFFFFF), eq(1), eq((short) 1), eq(true)); + verify(serverObserver).onPriorityRead(any(ChannelHandlerContext.class), eq(0x7FFFFFFF), + eq(1), eq((short) 1), eq(true)); } @Test @@ -181,7 +184,8 @@ public class Http2FrameRoundtripTest { frameWriter.writePushPromise(ctx(), newPromise(), 0x7FFFFFFF, 1, headers, 5); awaitRequests(); - verify(serverObserver).onPushPromiseRead(eq(0x7FFFFFFF), eq(1), eq(headers), eq(5)); + verify(serverObserver).onPushPromiseRead(any(ChannelHandlerContext.class), eq(0x7FFFFFFF), + eq(1), eq(headers), eq(5)); } @Test @@ -189,7 +193,8 @@ public class Http2FrameRoundtripTest { frameWriter.writeRstStream(ctx(), newPromise(), 0x7FFFFFFF, 0xFFFFFFFFL); awaitRequests(); - verify(serverObserver).onRstStreamRead(eq(0x7FFFFFFF), eq(0xFFFFFFFFL)); + verify(serverObserver).onRstStreamRead(any(ChannelHandlerContext.class), eq(0x7FFFFFFF), + eq(0xFFFFFFFFL)); } @Test @@ -202,7 +207,7 @@ public class Http2FrameRoundtripTest { frameWriter.writeSettings(ctx(), newPromise(), settings); awaitRequests(); - verify(serverObserver).onSettingsRead(eq(settings)); + verify(serverObserver).onSettingsRead(any(ChannelHandlerContext.class), eq(settings)); } @Test @@ -210,7 +215,8 @@ public class Http2FrameRoundtripTest { frameWriter.writeWindowUpdate(ctx(), newPromise(), 0x7FFFFFFF, 0x7FFFFFFF); awaitRequests(); - verify(serverObserver).onWindowUpdateRead(eq(0x7FFFFFFF), eq(0x7FFFFFFF)); + verify(serverObserver).onWindowUpdateRead(any(ChannelHandlerContext.class), eq(0x7FFFFFFF), + eq(0x7FFFFFFF)); } @Test @@ -259,101 +265,108 @@ public class Http2FrameRoundtripTest { @Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List out) throws Exception { - reader.readFrame(ctx.alloc(), in, new Http2FrameObserver() { + reader.readFrame(ctx, in, new Http2FrameObserver() { @Override - public void onDataRead(int streamId, ByteBuf data, int padding, - boolean endOfStream, boolean endOfSegment, boolean compressed) + public void onDataRead(ChannelHandlerContext ctx, int streamId, ByteBuf data, + int padding, boolean endOfStream, boolean endOfSegment, boolean compressed) throws Http2Exception { - observer.onDataRead(streamId, copy(data), padding, endOfStream, endOfSegment, - compressed); + observer.onDataRead(ctx, streamId, copy(data), padding, endOfStream, + endOfSegment, compressed); requestLatch.countDown(); } @Override - public void onHeadersRead(int streamId, Http2Headers headers, int padding, - boolean endStream, boolean endSegment) throws Http2Exception { - observer.onHeadersRead(streamId, headers, padding, endStream, endSegment); + public void onHeadersRead(ChannelHandlerContext ctx, int streamId, + Http2Headers headers, int padding, boolean endStream, boolean endSegment) + throws Http2Exception { + observer.onHeadersRead(ctx, streamId, headers, padding, endStream, endSegment); requestLatch.countDown(); } @Override - public void onHeadersRead(int streamId, Http2Headers headers, int streamDependency, - short weight, boolean exclusive, int padding, boolean endStream, - boolean endSegment) throws Http2Exception { - observer.onHeadersRead(streamId, headers, streamDependency, weight, exclusive, - padding, endStream, endSegment); + public void onHeadersRead(ChannelHandlerContext ctx, int streamId, + Http2Headers headers, int streamDependency, short weight, + boolean exclusive, int padding, boolean endStream, boolean endSegment) + throws Http2Exception { + observer.onHeadersRead(ctx, streamId, headers, streamDependency, weight, + exclusive, padding, endStream, endSegment); requestLatch.countDown(); } @Override - public void onPriorityRead(int streamId, int streamDependency, short weight, - boolean exclusive) throws Http2Exception { - observer.onPriorityRead(streamId, streamDependency, weight, exclusive); + public void onPriorityRead(ChannelHandlerContext ctx, int streamId, + int streamDependency, short weight, boolean exclusive) + throws Http2Exception { + observer.onPriorityRead(ctx, streamId, streamDependency, weight, exclusive); requestLatch.countDown(); } @Override - public void onRstStreamRead(int streamId, long errorCode) throws Http2Exception { - observer.onRstStreamRead(streamId, errorCode); + public void onRstStreamRead(ChannelHandlerContext ctx, int streamId, long errorCode) + throws Http2Exception { + observer.onRstStreamRead(ctx, streamId, errorCode); requestLatch.countDown(); } @Override - public void onSettingsAckRead() throws Http2Exception { - observer.onSettingsAckRead(); + public void onSettingsAckRead(ChannelHandlerContext ctx) throws Http2Exception { + observer.onSettingsAckRead(ctx); requestLatch.countDown(); } @Override - public void onSettingsRead(Http2Settings settings) throws Http2Exception { - observer.onSettingsRead(settings); + public void onSettingsRead(ChannelHandlerContext ctx, Http2Settings settings) + throws Http2Exception { + observer.onSettingsRead(ctx, settings); requestLatch.countDown(); } @Override - public void onPingRead(ByteBuf data) throws Http2Exception { - observer.onPingRead(copy(data)); + public void onPingRead(ChannelHandlerContext ctx, ByteBuf data) throws Http2Exception { + observer.onPingRead(ctx, copy(data)); requestLatch.countDown(); } @Override - public void onPingAckRead(ByteBuf data) throws Http2Exception { - observer.onPingAckRead(copy(data)); + public void onPingAckRead(ChannelHandlerContext ctx, ByteBuf data) throws Http2Exception { + observer.onPingAckRead(ctx, copy(data)); requestLatch.countDown(); } @Override - public void onPushPromiseRead(int streamId, int promisedStreamId, + public void onPushPromiseRead(ChannelHandlerContext ctx, int streamId, int promisedStreamId, Http2Headers headers, int padding) throws Http2Exception { - observer.onPushPromiseRead(streamId, promisedStreamId, headers, padding); + observer.onPushPromiseRead(ctx, streamId, promisedStreamId, headers, padding); requestLatch.countDown(); } @Override - public void onGoAwayRead(int lastStreamId, long errorCode, ByteBuf debugData) + public void onGoAwayRead(ChannelHandlerContext ctx, int lastStreamId, + long errorCode, ByteBuf debugData) throws Http2Exception { + observer.onGoAwayRead(ctx, lastStreamId, errorCode, copy(debugData)); + requestLatch.countDown(); + } + + @Override + public void onWindowUpdateRead(ChannelHandlerContext ctx, int streamId, + int windowSizeIncrement) throws Http2Exception { + observer.onWindowUpdateRead(ctx, streamId, windowSizeIncrement); + requestLatch.countDown(); + } + + @Override + public void onAltSvcRead(ChannelHandlerContext ctx, int streamId, long maxAge, + int port, ByteBuf protocolId, String host, String origin) throws Http2Exception { - observer.onGoAwayRead(lastStreamId, errorCode, copy(debugData)); + observer.onAltSvcRead(ctx, streamId, maxAge, port, copy(protocolId), host, + origin); requestLatch.countDown(); } @Override - public void onWindowUpdateRead(int streamId, int windowSizeIncrement) - throws Http2Exception { - observer.onWindowUpdateRead(streamId, windowSizeIncrement); - requestLatch.countDown(); - } - - @Override - public void onAltSvcRead(int streamId, long maxAge, int port, ByteBuf protocolId, - String host, String origin) throws Http2Exception { - observer.onAltSvcRead(streamId, maxAge, port, copy(protocolId), host, origin); - requestLatch.countDown(); - } - - @Override - public void onBlockedRead(int streamId) throws Http2Exception { - observer.onBlockedRead(streamId); + public void onBlockedRead(ChannelHandlerContext ctx, int streamId) throws Http2Exception { + observer.onBlockedRead(ctx, streamId); requestLatch.countDown(); } }); diff --git a/example/src/main/java/io/netty/example/http2/client/Http2ClientConnectionHandler.java b/example/src/main/java/io/netty/example/http2/client/Http2ClientConnectionHandler.java index f3a60673d7..dfd590db6a 100644 --- a/example/src/main/java/io/netty/example/http2/client/Http2ClientConnectionHandler.java +++ b/example/src/main/java/io/netty/example/http2/client/Http2ClientConnectionHandler.java @@ -80,8 +80,8 @@ public class Http2ClientConnectionHandler extends AbstractHttp2ConnectionHandler } @Override - public void onDataRead(int streamId, ByteBuf data, int padding, boolean endOfStream, - boolean endOfSegment, boolean compressed) throws Http2Exception { + public void onDataRead(ChannelHandlerContext ctx, int streamId, ByteBuf data, int padding, + boolean endOfStream, boolean endOfSegment, boolean compressed) throws Http2Exception { // Copy the data into the buffer. int available = data.readableBytes(); @@ -112,65 +112,68 @@ public class Http2ClientConnectionHandler extends AbstractHttp2ConnectionHandler } @Override - public void onHeadersRead(int streamId, Http2Headers headers, int padding, boolean endStream, + public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, + int padding, boolean endStream, boolean endSegment) throws Http2Exception { + } + + @Override + public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, + int streamDependency, short weight, boolean exclusive, int padding, boolean endStream, boolean endSegment) throws Http2Exception { } @Override - public void onHeadersRead(int streamId, Http2Headers headers, int streamDependency, - short weight, boolean exclusive, int padding, boolean endStream, boolean endSegment) + public void onPriorityRead(ChannelHandlerContext ctx, int streamId, int streamDependency, + short weight, boolean exclusive) throws Http2Exception { + } + + @Override + public void onRstStreamRead(ChannelHandlerContext ctx, int streamId, long errorCode) throws Http2Exception { } @Override - public void onPriorityRead(int streamId, int streamDependency, short weight, boolean exclusive) + public void onSettingsAckRead(ChannelHandlerContext ctx) throws Http2Exception { + } + + @Override + public void onSettingsRead(ChannelHandlerContext ctx, Http2Settings settings) throws Http2Exception { - } - - @Override - public void onRstStreamRead(int streamId, long errorCode) throws Http2Exception { - } - - @Override - public void onSettingsAckRead() throws Http2Exception { - } - - @Override - public void onSettingsRead(Http2Settings settings) throws Http2Exception { if (!initialized.isDone()) { initialized.setSuccess(); } } @Override - public void onPingRead(ByteBuf data) throws Http2Exception { + public void onPingRead(ChannelHandlerContext ctx, ByteBuf data) throws Http2Exception { } @Override - public void onPingAckRead(ByteBuf data) throws Http2Exception { + public void onPingAckRead(ChannelHandlerContext ctx, ByteBuf data) throws Http2Exception { } @Override - public void onPushPromiseRead(int streamId, int promisedStreamId, Http2Headers headers, - int padding) throws Http2Exception { + public void onPushPromiseRead(ChannelHandlerContext ctx, int streamId, int promisedStreamId, + Http2Headers headers, int padding) throws Http2Exception { } @Override - public void onGoAwayRead(int lastStreamId, long errorCode, ByteBuf debugData) + public void onGoAwayRead(ChannelHandlerContext ctx, int lastStreamId, long errorCode, + ByteBuf debugData) throws Http2Exception { + } + + @Override + public void onWindowUpdateRead(ChannelHandlerContext ctx, int streamId, int windowSizeIncrement) throws Http2Exception { } @Override - public void onWindowUpdateRead(int streamId, int windowSizeIncrement) throws Http2Exception { + public void onAltSvcRead(ChannelHandlerContext ctx, int streamId, long maxAge, int port, + ByteBuf protocolId, String host, String origin) throws Http2Exception { } @Override - public void onAltSvcRead(int streamId, long maxAge, int port, ByteBuf protocolId, String host, - String origin) throws Http2Exception { - } - - @Override - public void onBlockedRead(int streamId) throws Http2Exception { + public void onBlockedRead(ChannelHandlerContext ctx, int streamId) throws Http2Exception { } @Override diff --git a/example/src/main/java/io/netty/example/http2/server/HelloWorldHttp2Handler.java b/example/src/main/java/io/netty/example/http2/server/HelloWorldHttp2Handler.java index 2e1e4a9820..959af2b285 100644 --- a/example/src/main/java/io/netty/example/http2/server/HelloWorldHttp2Handler.java +++ b/example/src/main/java/io/netty/example/http2/server/HelloWorldHttp2Handler.java @@ -36,26 +36,26 @@ public class HelloWorldHttp2Handler extends AbstractHttp2ConnectionHandler { } @Override - public void onDataRead(int streamId, ByteBuf data, int padding, boolean endOfStream, - boolean endOfSegment, boolean compressed) throws Http2Exception { + public void onDataRead(ChannelHandlerContext ctx, int streamId, ByteBuf data, int padding, + boolean endOfStream, boolean endOfSegment, boolean compressed) throws Http2Exception { if (endOfStream) { sendResponse(ctx(), streamId); } } @Override - public void onHeadersRead(int streamId, - io.netty.handler.codec.http2.Http2Headers headers, int padding, - boolean endStream, boolean endSegment) throws Http2Exception { + public void onHeadersRead(ChannelHandlerContext ctx, int streamId, + io.netty.handler.codec.http2.Http2Headers headers, int padding, boolean endStream, + boolean endSegment) throws Http2Exception { if (endStream) { sendResponse(ctx(), streamId); } } @Override - public void onHeadersRead(int streamId, - io.netty.handler.codec.http2.Http2Headers headers, int streamDependency, - short weight, boolean exclusive, int padding, boolean endStream, boolean endSegment) + public void onHeadersRead(ChannelHandlerContext ctx, int streamId, + io.netty.handler.codec.http2.Http2Headers headers, int streamDependency, short weight, + boolean exclusive, int padding, boolean endStream, boolean endSegment) throws Http2Exception { if (endStream) { sendResponse(ctx(), streamId); @@ -63,52 +63,53 @@ public class HelloWorldHttp2Handler extends AbstractHttp2ConnectionHandler { } @Override - public void onPriorityRead(int streamId, int streamDependency, short weight, boolean exclusive) + public void onPriorityRead(ChannelHandlerContext ctx, int streamId, int streamDependency, + short weight, boolean exclusive) throws Http2Exception { + } + + @Override + public void onRstStreamRead(ChannelHandlerContext ctx, int streamId, long errorCode) throws Http2Exception { } @Override - public void onRstStreamRead(int streamId, long errorCode) throws Http2Exception { + public void onSettingsAckRead(ChannelHandlerContext ctx) throws Http2Exception { } @Override - public void onSettingsAckRead() throws Http2Exception { + public void onSettingsRead(ChannelHandlerContext ctx, Http2Settings settings) throws Http2Exception { } @Override - public void onSettingsRead(Http2Settings settings) throws Http2Exception { + public void onPingRead(ChannelHandlerContext ctx, ByteBuf data) throws Http2Exception { } @Override - public void onPingRead(ByteBuf data) throws Http2Exception { + public void onPingAckRead(ChannelHandlerContext ctx, ByteBuf data) throws Http2Exception { } @Override - public void onPingAckRead(ByteBuf data) throws Http2Exception { + public void onPushPromiseRead(ChannelHandlerContext ctx, int streamId, int promisedStreamId, + io.netty.handler.codec.http2.Http2Headers headers, int padding) throws Http2Exception { } @Override - public void onPushPromiseRead(int streamId, int promisedStreamId, - io.netty.handler.codec.http2.Http2Headers headers, int padding) + public void onGoAwayRead(ChannelHandlerContext ctx, int lastStreamId, long errorCode, + ByteBuf debugData) throws Http2Exception { + } + + @Override + public void onWindowUpdateRead(ChannelHandlerContext ctx, int streamId, int windowSizeIncrement) throws Http2Exception { } @Override - public void onGoAwayRead(int lastStreamId, long errorCode, ByteBuf debugData) - throws Http2Exception { + public void onAltSvcRead(ChannelHandlerContext ctx, int streamId, long maxAge, int port, + ByteBuf protocolId, String host, String origin) throws Http2Exception { } @Override - public void onWindowUpdateRead(int streamId, int windowSizeIncrement) throws Http2Exception { - } - - @Override - public void onAltSvcRead(int streamId, long maxAge, int port, ByteBuf protocolId, String host, - String origin) throws Http2Exception { - } - - @Override - public void onBlockedRead(int streamId) throws Http2Exception { + public void onBlockedRead(ChannelHandlerContext ctx, int streamId) throws Http2Exception { } @Override