use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpServerCodec in project moco by dreamhead.
the class MocoHttpServer method channelInitializer.
@Override
public final ChannelInitializer<SocketChannel> channelInitializer() {
return new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(final SocketChannel ch) {
ChannelPipeline pipeline = ch.pipeline();
if (serverSetting.isSecure()) {
pipeline.addFirst("ssl", serverSetting.sslHandler().get());
}
ServerConfig serverConfig = serverSetting.getServerConfig();
pipeline.addLast("codec", new HttpServerCodec(MAX_INITIAL_LINE_LENGTH, serverConfig.getHeaderSize(), MAX_CHUNK_SIZE, false));
pipeline.addLast("aggregator", new HttpObjectAggregator(serverConfig.getContentLength()));
pipeline.addLast("handler", new MocoHandler(serverSetting));
}
};
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpServerCodec 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 org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpServerCodec in project vert.x by eclipse.
the class Http2ClientTest method createH2CServer.
private ServerBootstrap createH2CServer(BiFunction<Http2ConnectionDecoder, Http2ConnectionEncoder, Http2FrameListener> handler, boolean upgrade) {
ServerBootstrap bootstrap = new ServerBootstrap();
bootstrap.channel(NioServerSocketChannel.class);
bootstrap.group(new NioEventLoopGroup());
bootstrap.childHandler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) throws Exception {
if (upgrade) {
HttpServerCodec sourceCodec = new HttpServerCodec();
HttpServerUpgradeHandler.UpgradeCodecFactory upgradeCodecFactory = protocol -> {
if (AsciiString.contentEquals(Http2CodecUtil.HTTP_UPGRADE_PROTOCOL_NAME, protocol)) {
return new Http2ServerUpgradeCodec(createHttpConnectionHandler(handler));
} else {
return null;
}
};
ch.pipeline().addLast(sourceCodec);
ch.pipeline().addLast(new HttpServerUpgradeHandler(sourceCodec, upgradeCodecFactory));
} else {
Http2ConnectionHandler clientHandler = createHttpConnectionHandler(handler);
ch.pipeline().addLast("handler", clientHandler);
}
}
});
return bootstrap;
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpServerCodec in project async-http-client by AsyncHttpClient.
the class HttpStaticFileServerInitializer method initChannel.
@Override
public void initChannel(SocketChannel ch) {
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast(new HttpServerCodec());
pipeline.addLast(new HttpObjectAggregator(65536));
pipeline.addLast(new ChunkedWriteHandler());
pipeline.addLast(new HttpStaticFileServerHandler());
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpServerCodec in project ambry by linkedin.
the class NettyServerChannelInitializer method initChannel.
@Override
protected void initChannel(SocketChannel ch) throws Exception {
// If channel handler implementations are not annotated with @Sharable, Netty creates a new instance of every class
// in the pipeline for every connection.
// i.e. if there are a 1000 active connections there will be a 1000 NettyMessageProcessor instances.
ChannelPipeline pipeline = ch.pipeline();
// connection stats handler to track connection related metrics
pipeline.addLast("connectionStatsHandler", connectionStatsHandler);
// if SSL is enabled, add an SslHandler before the HTTP codec
if (sslFactory != null) {
InetSocketAddress peerAddress = ch.remoteAddress();
pipeline.addLast("sslHandler", new SslHandler(sslFactory.createSSLEngine(peerAddress.getHostName(), peerAddress.getPort(), SSLFactory.Mode.SERVER)));
}
pipeline.addLast("codec", new HttpServerCodec(nettyConfig.nettyServerMaxInitialLineLength, nettyConfig.nettyServerMaxHeaderSize, nettyConfig.nettyServerMaxChunkSize)).addLast("healthCheckHandler", new HealthCheckHandler(restServerState, nettyMetrics)).addLast("publicAccessLogHandler", new PublicAccessLogHandler(publicAccessLogger, nettyMetrics)).addLast("idleStateHandler", new IdleStateHandler(0, 0, nettyConfig.nettyServerIdleTimeSeconds)).addLast("chunker", new ChunkedWriteHandler()).addLast("processor", new NettyMessageProcessor(nettyMetrics, nettyConfig, requestHandler));
}
Aggregations