The server channel is expected to set the proper 'Connection' header if it can handle persistent connections. HttpServerKeepAliveHandler will automatically close the channel for any LastHttpContent that corresponds to a client
request for closing the connection, or if the HttpResponse associated with that LastHttpContent requested closing the
connection or didn't have a self defined message length.
Since HttpServerKeepAliveHandler expects HttpObjects it should be added after HttpServerCodec
but before any other handlers that might send a HttpResponse.
ChannelPipelinep = ...; ... p.addLast("serverCodec", newHttpServerCodec()); p.addLast("httpKeepAlive", newHttpServerKeepAliveHandler()); p.addLast("aggregator", newHttpObjectAggregator(1048576)); ... p.addLast("handler", new HttpRequestHandler());
| Modifier and Type | Field and Description |
|---|---|
| private static final String | |
| private int | |
| private boolean |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | channelRead(ChannelHandlerContext ctx, Object msg)
Overrides default io. Channel has read a message from the peer.
|
| private static boolean | |
| private static boolean | |
| private static boolean | Returns: true if the response has a self defined message length.The HttpResponse to check response)Keep-alive only works if the client can detect when the message has ended without relying on the connection being closed. |
| private boolean | |
| private void | |
| public Future | write(ChannelHandlerContext
the ctx, Object ChannelHandlerContext for which the write operation is madethe message to write msg)Overrides default io. |
| MULTIPART_PREFIX | back to summary |
|---|---|
| private static final String MULTIPART_PREFIX | |
| pendingResponses | back to summary |
|---|---|
| private int pendingResponses | |
| persistentConnection | back to summary |
|---|---|
| private boolean persistentConnection | |
| HttpServerKeepAliveHandler | back to summary |
|---|---|
| public HttpServerKeepAliveHandler() | |
| channelRead | back to summary |
|---|---|
| public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception Overrides default io. Doc from io. Invoked when the current
| |
| isInformational | back to summary |
|---|---|
| private static boolean isInformational(HttpResponse response) | |
| isMultipart | back to summary |
|---|---|
| private static boolean isMultipart(HttpResponse response) | |
| isSelfDefinedMessageLength | back to summary |
|---|---|
| private static boolean isSelfDefinedMessageLength(HttpResponse response) Keep-alive only works if the client can detect when the message has ended without relying on the connection being closed.
| |
| shouldKeepAlive | back to summary |
|---|---|
| private boolean shouldKeepAlive() | |
| trackResponse | back to summary |
|---|---|
| private void trackResponse(HttpResponse response) | |
| write | back to summary |
|---|---|
| public Future Overrides default io. Doc from io. Called once a write operation is made. The write operation will write the messages through the
| |