public class HttpServerKeepAliveHandler extends ChannelDuplexHandler
如果服务器通道可以处理持续连接,则需要设置正确的“连接”标头。 HttpServerKeepAliveHandler将自动关闭对应于客户端请求关闭连接的任何LastHttpContent的通道,或者与该LastHttpContent关联的HttpResponse请求关闭连接或没有自定义消息长度。
由于HttpServerKeepAliveHandler预计HttpObject s应在HttpServerCodec之后添加,但在可能发送HttpResponse的任何其他处理程序之前添加。
ChannelPipelinep = ...; ... p.addLast("serverCodec", newHttpServerCodec()); p.addLast("httpKeepAlive", newHttpServerKeepAliveHandler()); p.addLast("aggregator", newHttpObjectAggregator(1048576)); ... p.addLast("handler", new HttpRequestHandler());
ChannelHandler.Sharable| Constructor and Description |
|---|
HttpServerKeepAliveHandler() |
| Modifier and Type | Method and Description |
|---|---|
void |
channelRead(ChannelHandlerContext ctx, java.lang.Object msg)
|
void |
write(ChannelHandlerContext ctx, java.lang.Object msg, ChannelPromise promise)
|
bind, close, connect, deregister, disconnect, flush, readchannelActive, channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggeredensureNotSharable, handlerAdded, handlerRemoved, isSharableclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitexceptionCaught, handlerAdded, handlerRemovedpublic void channelRead(ChannelHandlerContext ctx, java.lang.Object msg) throws java.lang.Exception
ChannelInboundHandlerAdapter
ChannelHandlerContext.fireChannelRead(Object)转发到ChannelPipeline中的下一个ChannelInboundHandler 。
子类可以重写此方法来更改行为。
channelRead在界面
ChannelInboundHandler
channelRead
ChannelInboundHandlerAdapter
java.lang.Exception
public void write(ChannelHandlerContext ctx, java.lang.Object msg, ChannelPromise promise) throws java.lang.Exception
ChannelDuplexHandler
ChannelOutboundInvoker.write(Object, ChannelPromise)转发至ChannelPipeline中的下一个ChannelOutboundHandler 。
子类可以重写此方法来更改行为。
write在界面
ChannelOutboundHandler
write ,等级
ChannelDuplexHandler
ctx - 为其写入操作的ChannelHandlerContext
msg - 写信息
promise - 在操作完成后通知ChannelPromise
java.lang.Exception - 发生错误时抛出
Copyright © 2008–2018 The Netty Project. All rights reserved.