public class HttpServerKeepAliveHandler extends ChannelDuplexHandler
如果服务器通道可以处理持续连接,则需要设置正确的“连接”标头。 HttpServerKeepAliveHandler
将自动关闭对应于客户端请求关闭连接的任何LastHttpContent的通道,或者与该LastHttpContent关联的HttpResponse请求关闭连接或没有自定义消息长度。
由于HttpServerKeepAliveHandler
预计HttpObject
s应在HttpServerCodec
之后添加,但在可能发送HttpResponse
的任何其他处理程序之前添加。
ChannelPipeline
p = ...; ... 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, read
channelActive, channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggered
ensureNotSharable, handlerAdded, handlerRemoved, isSharable
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
exceptionCaught, handlerAdded, handlerRemoved
public 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.