use of io.netty.handler.codec.http2.Http2Codec in project jersey by jersey.
the class JerseyServerInitializer method configureClearText.
/**
* Configure the pipeline for a cleartext upgrade from HTTP to HTTP/2.
*/
private void configureClearText(SocketChannel ch) {
final ChannelPipeline p = ch.pipeline();
final HttpServerCodec sourceCodec = new HttpServerCodec();
p.addLast(sourceCodec);
p.addLast(new HttpServerUpgradeHandler(sourceCodec, new HttpServerUpgradeHandler.UpgradeCodecFactory() {
@Override
public HttpServerUpgradeHandler.UpgradeCodec newUpgradeCodec(CharSequence protocol) {
if (AsciiString.contentEquals(Http2CodecUtil.HTTP_UPGRADE_PROTOCOL_NAME, protocol)) {
return new Http2ServerUpgradeCodec(new Http2Codec(true, new JerseyHttp2ServerHandler(baseUri, container)));
} else {
return null;
}
}
}));
p.addLast(new SimpleChannelInboundHandler<HttpMessage>() {
@Override
protected void channelRead0(ChannelHandlerContext ctx, HttpMessage msg) throws Exception {
// If this handler is hit then no upgrade has been attempted and the client is just talking HTTP.
// "Directly talking: " + msg.protocolVersion() + " (no upgrade was attempted)");
ChannelPipeline pipeline = ctx.pipeline();
ChannelHandlerContext thisCtx = pipeline.context(this);
pipeline.addAfter(thisCtx.name(), null, new JerseyServerHandler(baseUri, container));
pipeline.replace(this, null, new ChunkedWriteHandler());
ctx.fireChannelRead(msg);
}
});
}
use of io.netty.handler.codec.http2.Http2Codec in project rest.li by linkedin.
the class Http2InitializerHandler method configureHttpPipeline.
/**
* Sets up HTTP/2 over TCP through protocol upgrade (h2c) pipeline
*/
private void configureHttpPipeline(ChannelHandlerContext ctx, Request request) throws Exception {
Http2StreamCodec http2Codec = new Http2StreamCodecBuilder().connection(_connection).maxContentLength(_maxResponseSize).maxHeaderSize(_maxHeaderSize).gracefulShutdownTimeoutMillis(_gracefulShutdownTimeout).streamingTimeout(_streamingTimeout).scheduler(_scheduler).build();
HttpClientCodec sourceCodec = new HttpClientCodec(MAX_INITIAL_LINE_LENGTH, _maxHeaderSize, _maxChunkSize);
Http2ClientUpgradeCodec targetCodec = new Http2ClientUpgradeCodec(http2Codec);
HttpClientUpgradeHandler upgradeCodec = new HttpClientUpgradeHandler(sourceCodec, targetCodec, MAX_CLIENT_UPGRADE_CONTENT_LENGTH);
Http2SchemeHandler schemeHandler = new Http2SchemeHandler(HttpScheme.HTTP.toString());
String host = request.getURI().getAuthority();
int port = request.getURI().getPort();
String path = request.getURI().getPath();
Http2UpgradeHandler upgradeHandler = new Http2UpgradeHandler(host, port, path);
Http2StreamResponseHandler responseHandler = new Http2StreamResponseHandler();
Http2ChannelPoolHandler channelPoolHandler = new Http2ChannelPoolHandler();
ctx.pipeline().addBefore(ctx.name(), "sourceCodec", sourceCodec);
ctx.pipeline().addBefore(ctx.name(), "upgradeCodec", upgradeCodec);
ctx.pipeline().addBefore(ctx.name(), "upgradeHandler", upgradeHandler);
ctx.pipeline().addBefore(ctx.name(), "schemeHandler", schemeHandler);
ctx.pipeline().addBefore(ctx.name(), "responseHandler", responseHandler);
ctx.pipeline().addBefore(ctx.name(), "channelHandler", channelPoolHandler);
_setupComplete = true;
}
Aggregations