use of io.netty.handler.codec.http2.Http2Connection in project rest.li by linkedin.
the class Http2ClientPipelineInitializer method initChannel.
@Override
protected void initChannel(NioSocketChannel channel) throws Exception {
Http2Connection connection = new DefaultHttp2Connection(false);
channel.attr(HTTP2_CONNECTION_ATTR_KEY).set(connection);
channel.attr(CALLBACK_ATTR_KEY).set(connection.newKey());
channel.attr(CHANNEL_POOL_HANDLE_ATTR_KEY).set(connection.newKey());
if (_sslParameters == null) {
// clear text
configureHttpPipeline(channel, connection);
} else {
// TLS
configureHttpsPipeline(channel, connection);
}
}
use of io.netty.handler.codec.http2.Http2Connection in project rest.li by linkedin.
the class Http2PipelinePropertyUtil method doAction.
private static <T> T doAction(ChannelHandlerContext ctx, Http2Connection http2Connection, int streamId, AttributeKey<Http2Connection.PropertyKey> key, BiFunction<Http2Stream, Http2Connection.PropertyKey, T> function) {
ArgumentUtil.notNull(http2Connection, "http2Connection");
final Http2Stream stream = http2Connection.stream(streamId);
if (stream == null) {
LOG.debug("Stream {} no longer exists", streamId);
return null;
}
final Http2Connection.PropertyKey propertyKey = getKey(ctx, key);
if (propertyKey == null) {
LOG.debug("Property key {} is not valid", key);
return null;
}
return function.apply(stream, propertyKey);
}
use of io.netty.handler.codec.http2.Http2Connection in project jetty.project by eclipse.
the class AbstractHTTP2ServerConnectionFactory method newConnection.
@Override
public Connection newConnection(Connector connector, EndPoint endPoint) {
ServerSessionListener listener = newSessionListener(connector, endPoint);
Generator generator = new Generator(connector.getByteBufferPool(), getMaxDynamicTableSize(), getMaxHeaderBlockFragment());
FlowControlStrategy flowControl = getFlowControlStrategyFactory().newFlowControlStrategy();
HTTP2ServerSession session = new HTTP2ServerSession(connector.getScheduler(), endPoint, generator, listener, flowControl);
session.setMaxLocalStreams(getMaxConcurrentStreams());
session.setMaxRemoteStreams(getMaxConcurrentStreams());
// For a single stream in a connection, there will be a race between
// the stream idle timeout and the connection idle timeout. However,
// the typical case is that the connection will be busier and the
// stream idle timeout will expire earlier than the connection's.
long streamIdleTimeout = getStreamIdleTimeout();
if (streamIdleTimeout <= 0)
streamIdleTimeout = endPoint.getIdleTimeout();
session.setStreamIdleTimeout(streamIdleTimeout);
session.setInitialSessionRecvWindow(getInitialSessionRecvWindow());
ServerParser parser = newServerParser(connector, session);
HTTP2Connection connection = new HTTP2ServerConnection(connector.getByteBufferPool(), connector.getExecutor(), endPoint, httpConfiguration, parser, session, getInputBufferSize(), listener);
connection.addListener(connectionListener);
return configure(connection, connector, endPoint);
}
use of io.netty.handler.codec.http2.Http2Connection in project vert.x by eclipse.
the class Http2ServerTest method testPriorKnowledge.
@Test
public void testPriorKnowledge() throws Exception {
server.close();
server = vertx.createHttpServer(new HttpServerOptions().setPort(DEFAULT_HTTP_PORT).setHost(DEFAULT_HTTP_HOST));
server.requestHandler(req -> {
req.response().end("Hello World");
});
startServer();
TestClient client = new TestClient() {
@Override
protected ChannelInitializer channelInitializer(int port, String host, Consumer<Connection> handler) {
return new ChannelInitializer() {
@Override
protected void initChannel(Channel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
Http2Connection connection = new DefaultHttp2Connection(false);
TestClientHandlerBuilder clientHandlerBuilder = new TestClientHandlerBuilder(handler);
TestClientHandler clientHandler = clientHandlerBuilder.build(connection);
p.addLast(clientHandler);
}
};
}
};
ChannelFuture fut = client.connect(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, request -> {
request.decoder.frameListener(new Http2EventAdapter() {
@Override
public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int streamDependency, short weight, boolean exclusive, int padding, boolean endStream) throws Http2Exception {
vertx.runOnContext(v -> {
testComplete();
});
}
});
int id = request.nextStreamId();
request.encoder.writeHeaders(request.context, id, GET("/"), 0, true, request.context.newPromise());
request.context.flush();
});
fut.sync();
await();
}
use of io.netty.handler.codec.http2.Http2Connection in project vert.x by eclipse.
the class Http2ConnectionBase method checkShutdownHandler.
// Private
private void checkShutdownHandler() {
if (!shutdown) {
Http2Connection conn = handler.connection();
if ((conn.goAwayReceived() || conn.goAwaySent()) && conn.numActiveStreams() == 0) {
shutdown = true;
Handler<Void> handler = shutdownHandler;
if (handler != null) {
context.executeFromIO(() -> {
shutdownHandler.handle(null);
});
}
}
}
}
Aggregations