下面列出了怎么用 io.netty.handler.codec.http.HttpServerExpectContinueHandler 的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
protected void initChannel(SocketChannel ch) {
ChannelPipeline pipeline = ch.pipeline();
try {
if (sslCtx != null) {
pipeline.addLast(sslCtx.newHandler(ch.alloc()));
}
pipeline.addLast(new HttpServerCodec());
pipeline.addLast(new HttpServerExpectContinueHandler());
if (useGZIP) {
pipeline.addLast(new HttpContentCompressor());
}
if (isWebSocket) {
pipeline.addLast(new WebSocketHandler(blade));
}
pipeline.addLast(new MergeRequestHandler());
pipeline.addLast(httpServerHandler);
} catch (Exception e) {
log.error("Add channel pipeline error", e);
}
}
@Override
public void initChannel(SocketChannel ch) {
ChannelPipeline p = ch.pipeline();
if (sslCtx != null) {
p.addLast(sslCtx.newHandler(ch.alloc()));
}
p.addLast(new HttpServerCodec());
p.addLast(new HttpServerExpectContinueHandler());
p.addLast(new HttpHelloWorldServerHandler());
}
@Override
public void initChannel(SocketChannel ch) {
ChannelPipeline p = ch.pipeline();
/**
* 或者使用HttpRequestDecoder & HttpResponseEncoder
*/
p.addLast(new HttpServerCodec());
/**
* 在处理POST消息体时需要加上
*/
p.addLast(new HttpObjectAggregator(1024*1024));
p.addLast(new HttpServerExpectContinueHandler());
p.addLast(new HttpHelloWorldServerHandler());
}
@Override
public void buildChannelPipeline(ChannelPipeline pipeline) {
pipeline.addLast(new HttpServerCodec());
pipeline.addLast(new HttpServerExpectContinueHandler());
pipeline.addLast(MsgOutboundHandler.INSTANCE);
if(socketConfiguration.getProtocolType() == SocketConfiguration.ProtocolType.TEXT){
pipeline.addLast(new DefaultTextWebSocketServerHandler());
}else{
pipeline.addLast(new ProtocolWebSocketServerHandler());
}
}
@Override
public void initChannel(SocketChannel ch) {
ChannelPipeline p = ch.pipeline();
if (sslCtx != null) {
p.addLast(sslCtx.newHandler(ch.alloc()));
}
p.addLast(new HttpServerCodec());
p.addLast(new HttpServerExpectContinueHandler());
p.addLast(new HttpHelloWorldServerHandler());
}
@Override
public void handlePipeline(ChannelPipeline pipeline) {
pipeline.addLast(new HttpServerCodec());
pipeline.addLast(new HttpServerExpectContinueHandler());
pipeline.addLast(new HttpObjectAggregator(65536));
pipeline.addLast(new ChunkedWriteHandler());
pipeline.addLast(new HttpContentCompressor());
pipeline.addLast(new HttpRequestHandler(sslContextManager));
}
private void setHttpInterceptor(ChannelHandlerContext ctx, boolean ssl) {
ctx.pipeline().addLast("http-codec", new HttpServerCodec());
ctx.pipeline().addLast(new HttpServerExpectContinueHandler());
ctx.pipeline().addLast("replay-handler", new ReplayHandler(outboundChannel));
outboundChannel.pipeline().addLast("http-codec", new HttpClientCodec());
var httpUpgradeHandler = new HttpUpgradeHandler(ssl, address, messageListener, ctx.pipeline());
outboundChannel.pipeline().addLast("http-upgrade-handler", httpUpgradeHandler);
var httpInterceptor = new HttpInterceptor(ssl, address, messageListener);
outboundChannel.pipeline().addLast("http-interceptor", httpInterceptor);
outboundChannel.pipeline().addLast("replay-handler", new ReplayHandler(ctx.channel()));
}
@Provides
@HttpWhoisProtocol
static ImmutableList<Provider<? extends ChannelHandler>> providerHttpWhoisHandlerProviders(
Provider<HttpServerCodec> httpServerCodecProvider,
Provider<HttpServerExpectContinueHandler> httpServerExpectContinueHandlerProvider,
@HttpWhoisProtocol Provider<WebWhoisRedirectHandler> webWhoisRedirectHandlerProvides) {
return ImmutableList.of(
httpServerCodecProvider,
httpServerExpectContinueHandlerProvider,
webWhoisRedirectHandlerProvides);
}
@Provides
@HttpsWhoisProtocol
static ImmutableList<Provider<? extends ChannelHandler>> providerHttpsWhoisHandlerProviders(
@HttpsWhoisProtocol
Provider<SslServerInitializer<NioSocketChannel>> sslServerInitializerProvider,
Provider<HttpServerCodec> httpServerCodecProvider,
Provider<HttpServerExpectContinueHandler> httpServerExpectContinueHandlerProvider,
@HttpsWhoisProtocol Provider<WebWhoisRedirectHandler> webWhoisRedirectHandlerProvides) {
return ImmutableList.of(
sslServerInitializerProvider,
httpServerCodecProvider,
httpServerExpectContinueHandlerProvider,
webWhoisRedirectHandlerProvides);
}
@Override
public void handlePipeline(ChannelPipeline pipeline) {
pipeline.addLast(new HttpServerCodec());
pipeline.addLast("", new HttpServerExpectContinueHandler());
pipeline.addLast(new HttpProxyHandler(messageListener, proxyHandlerSupplier));
}
@Provides
static HttpServerExpectContinueHandler provideHttpServerExpectContinueHandler() {
return new HttpServerExpectContinueHandler();
}