@Override public void onSettingsRead(ChannelHandlerContext ctx, Http2Settings settings) throws Http2Exception { connection = connectionFactory.apply(this); if (useDecompressor) { decoder().frameListener(new DelegatingDecompressorFrameListener(decoder().connection(), connection)); } else { decoder().frameListener(connection); } connection.onSettingsRead(ctx, settings); if (addHandler != null) { addHandler.handle(connection); } }
Http2Decompressor decompressor = decompressor(stream); if (decompressor == null && !endOfStream) { contentEncoding = IDENTITY; final EmbeddedChannel channel = newContentDecompressor(ctx, contentEncoding); if (channel != null) { decompressor = new Http2Decompressor(channel); CharSequence targetContentEncoding = getTargetContentEncoding(contentEncoding); if (IDENTITY.contentEqualsIgnoreCase(targetContentEncoding)) { headers.remove(CONTENT_ENCODING);
@Override public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int padding, boolean endStream) throws Http2Exception { initDecompressor(ctx, streamId, headers, endStream); listener.onHeadersRead(ctx, streamId, headers, padding, endStream); }
throws Http2Exception { final Http2Stream stream = connection.stream(streamId); final Http2Decompressor decompressor = decompressor(stream); if (decompressor == null) { ByteBuf buf = nextReadableBuf(channel); if (buf == null && endOfStream && channel.finish()) { buf = nextReadableBuf(channel); decompressor.incrementDecompressedBytes(padding); for (;;) { ByteBuf nextBuf = nextReadableBuf(channel); boolean decompressedEndOfStream = nextBuf == null && endOfStream; if (decompressedEndOfStream && channel.finish()) { nextBuf = nextReadableBuf(channel); decompressedEndOfStream = nextBuf == null;
@Override public void onStreamRemoved(Http2Stream stream) { final Http2Decompressor decompressor = decompressor(stream); if (decompressor != null) { cleanup(decompressor); } } });
throws Http2Exception { final Http2Stream stream = connection.stream(streamId); final Http2Decompressor decompressor = decompressor(stream); if (decompressor == null) { ByteBuf buf = nextReadableBuf(channel); if (buf == null && endOfStream && channel.finish()) { buf = nextReadableBuf(channel); decompressor.incrementDecompressedBytes(padding); for (;;) { ByteBuf nextBuf = nextReadableBuf(channel); boolean decompressedEndOfStream = nextBuf == null && endOfStream; if (decompressedEndOfStream && channel.finish()) { nextBuf = nextReadableBuf(channel); decompressedEndOfStream = nextBuf == null;
@Override public boolean consumeBytes(Http2Stream stream, int numBytes) throws Http2Exception { Http2Decompressor decompressor = decompressor(stream); if (decompressor != null) { // Convert the decompressed bytes to compressed (on the wire) bytes. numBytes = decompressor.consumeBytes(stream.id(), numBytes); } try { return flowController.consumeBytes(stream, numBytes); } catch (Http2Exception e) { throw e; } catch (Throwable t) { // The stream should be closed at this point. We have already changed our state tracking the compressed // bytes, and there is no guarantee we can recover if the underlying flow controller throws. throw streamError(stream.id(), INTERNAL_ERROR, t, "Error while returning bytes to flow control window"); } }
@Override public void initChannel(SocketChannel ch) throws Exception { final Http2Connection connection = new DefaultHttp2Connection(false); connectionHandler = new HttpToHttp2ConnectionHandlerBuilder() .frameListener(new DelegatingDecompressorFrameListener( connection, new InboundHttp2ToHttpAdapterBuilder(connection) .maxContentLength(transportConfig.getPayload()) .propagateSettings(true) .build())) .connection(connection) .build(); responseHandler = new Http2ClientChannelHandler(); settingsHandler = new Http2SettingsHandler(ch.newPromise()); String protocol = transportConfig.getProviderInfo().getProtocolType(); if (RpcConstants.PROTOCOL_TYPE_H2.equals(protocol)) { configureSsl(ch); } else if (RpcConstants.PROTOCOL_TYPE_H2C.equals(protocol)) { if (!useH2cPriorKnowledge) { configureClearTextWithHttpUpgrade(ch); } else { configureClearTextWithPriorKnowledge(ch); } } }
Http2Decompressor decompressor = decompressor(stream); if (decompressor == null && !endOfStream) { contentEncoding = IDENTITY; final EmbeddedChannel channel = newContentDecompressor(ctx, contentEncoding); if (channel != null) { decompressor = new Http2Decompressor(channel); CharSequence targetContentEncoding = getTargetContentEncoding(contentEncoding); if (IDENTITY.contentEqualsIgnoreCase(targetContentEncoding)) { headers.remove(CONTENT_ENCODING);
throws Http2Exception { final Http2Stream stream = connection.stream(streamId); final Http2Decompressor decompressor = decompressor(stream); if (decompressor == null) { ByteBuf buf = nextReadableBuf(channel); if (buf == null && endOfStream && channel.finish()) { buf = nextReadableBuf(channel); decompressor.incrementDecompressedBytes(padding); for (;;) { ByteBuf nextBuf = nextReadableBuf(channel); boolean decompressedEndOfStream = nextBuf == null && endOfStream; if (decompressedEndOfStream && channel.finish()) { nextBuf = nextReadableBuf(channel); decompressedEndOfStream = nextBuf == null;
@Override public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int streamDependency, short weight, boolean exclusive, int padding, boolean endStream) throws Http2Exception { initDecompressor(ctx, streamId, headers, endStream); listener.onHeadersRead(ctx, streamId, headers, streamDependency, weight, exclusive, padding, endStream); }
@Override public void onStreamRemoved(Http2Stream stream) { final Http2Decompressor decompressor = decompressor(stream); if (decompressor != null) { cleanup(decompressor); } } });
@Override public void initChannel(SocketChannel ch) throws Exception { final Http2Connection connection = new DefaultHttp2Connection(false); connectionHandler = new HttpToHttp2ConnectionHandlerBuilder() .frameListener(new DelegatingDecompressorFrameListener( connection, new InboundHttp2ToHttpAdapterBuilder(connection) .maxContentLength(transportConfig.getPayload()) .propagateSettings(true) .build())) .connection(connection) .build(); responseHandler = new Http2ClientChannelHandler(); settingsHandler = new Http2SettingsHandler(ch.newPromise()); String protocol = transportConfig.getProviderInfo().getProtocolType(); if (RpcConstants.PROTOCOL_TYPE_H2.equals(protocol)) { configureSsl(ch); } else if (RpcConstants.PROTOCOL_TYPE_H2C.equals(protocol)) { if (!useH2cPriorKnowledge) { configureClearTextWithHttpUpgrade(ch); } else { configureClearTextWithPriorKnowledge(ch); } } }
Http2Decompressor decompressor = decompressor(stream); if (decompressor == null && !endOfStream) { contentEncoding = IDENTITY; final EmbeddedChannel channel = newContentDecompressor(ctx, contentEncoding); if (channel != null) { decompressor = new Http2Decompressor(channel); CharSequence targetContentEncoding = getTargetContentEncoding(contentEncoding); if (IDENTITY.contentEqualsIgnoreCase(targetContentEncoding)) { headers.remove(CONTENT_ENCODING);
@Override public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int padding, boolean endStream) throws Http2Exception { initDecompressor(ctx, streamId, headers, endStream); listener.onHeadersRead(ctx, streamId, headers, padding, endStream); }
@Override public void onStreamRemoved(Http2Stream stream) { final Http2Decompressor decompressor = decompressor(stream); if (decompressor != null) { cleanup(decompressor); } } });
@Override public void initChannel(SocketChannel ch) throws Exception { final ChannelPipeline p = ch.pipeline(); final Http2Connection conn = new DefaultHttp2Connection(false); final HttpToHttp2ConnectionHandler connHandler = new HttpToHttp2ConnectionHandlerBuilder() .connection(conn) .frameListener(new DelegatingDecompressorFrameListener( conn, new InboundHttp2ToHttpAdapterBuilder(conn) .maxContentLength(Integer.MAX_VALUE) .propagateSettings(true).build())) .build(); clientHandler = new THttp2ClientHandler(ch.eventLoop()); if (sslCtx != null) { p.addLast(sslCtx.newHandler(p.channel().alloc())); p.addLast(connHandler); configureEndOfPipeline(p); } else { final Http1ClientCodec sourceCodec = new Http1ClientCodec(); final HttpClientUpgradeHandler upgradeHandler = new HttpClientUpgradeHandler( sourceCodec, new Http2ClientUpgradeCodec(connHandler), 65536); p.addLast(sourceCodec, upgradeHandler, new UpgradeRequestHandler()); } }
@Override public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int streamDependency, short weight, boolean exclusive, int padding, boolean endStream) throws Http2Exception { initDecompressor(ctx, streamId, headers, endStream); listener.onHeadersRead(ctx, streamId, headers, streamDependency, weight, exclusive, padding, endStream); }
@Override public boolean consumeBytes(Http2Stream stream, int numBytes) throws Http2Exception { Http2Decompressor decompressor = decompressor(stream); if (decompressor != null) { // Convert the decompressed bytes to compressed (on the wire) bytes. numBytes = decompressor.consumeBytes(stream.id(), numBytes); } try { return flowController.consumeBytes(stream, numBytes); } catch (Http2Exception e) { throw e; } catch (Throwable t) { // The stream should be closed at this point. We have already changed our state tracking the compressed // bytes, and there is no guarantee we can recover if the underlying flow controller throws. throw streamError(stream.id(), INTERNAL_ERROR, t, "Error while returning bytes to flow control window"); } }
@Override public void onSettingsRead(ChannelHandlerContext ctx, Http2Settings settings) throws Http2Exception { connection = connectionFactory.apply(this); if (useDecompressor) { decoder().frameListener(new DelegatingDecompressorFrameListener(decoder().connection(), connection)); } else { decoder().frameListener(connection); } connection.onSettingsRead(ctx, settings); if (addHandler != null) { addHandler.handle(connection); } }