private CharSequence connectionHeader(boolean keepAlive, HttpVersion httpVersion) { if (httpVersion.isKeepAliveDefault()) { return keepAlive ? null : HttpHeaderValues.CLOSE; } else { return keepAlive ? HttpHeaderValues.KEEP_ALIVE : null; } } }
if (httpVersion.isKeepAliveDefault()) { if (keepAlive) { h.remove(HttpHeaderNames.CONNECTION);
/** * Returns {@code true} if and only if the connection can remain open and * thus 'kept alive'. This methods respects the value of the. * {@code "Connection"} header first and then the return value of * {@link HttpVersion#isKeepAliveDefault()}. */ public static boolean isKeepAlive(HttpMessage message) { CharSequence connection = message.headers().get(HttpHeaderNames.CONNECTION); if (connection != null && HttpHeaderValues.CLOSE.contentEqualsIgnoreCase(connection)) { return false; } if (message.protocolVersion().isKeepAliveDefault()) { return !HttpHeaderValues.CLOSE.contentEqualsIgnoreCase(connection); } else { return HttpHeaderValues.KEEP_ALIVE.contentEqualsIgnoreCase(connection); } }
private void writeFinalNettyResponse(MutableHttpResponse<?> message, AtomicReference<HttpRequest<?>> requestReference, ChannelHandlerContext context) { NettyMutableHttpResponse nettyHttpResponse = (NettyMutableHttpResponse) message; FullHttpResponse nettyResponse = nettyHttpResponse.getNativeResponse(); HttpRequest<?> httpRequest = requestReference.get(); io.netty.handler.codec.http.HttpHeaders nettyHeaders = nettyResponse.headers(); // default Connection header if not set explicitly if (!nettyHeaders.contains(HttpHeaderNames.CONNECTION)) { boolean expectKeepAlive = nettyResponse.protocolVersion().isKeepAliveDefault() || httpRequest.getHeaders().isKeepAlive(); HttpStatus status = nettyHttpResponse.status(); if (!expectKeepAlive || status.getCode() > 299) { nettyHeaders.add(HttpHeaderNames.CONNECTION, HttpHeaderValues.CLOSE); } else { nettyHeaders.add(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE); } } // default to Transfer-Encoding: chunked if Content-Length not set or not already set if (!nettyHeaders.contains(HttpHeaderNames.CONTENT_LENGTH) && !nettyHeaders.contains(HttpHeaderNames.TRANSFER_ENCODING)) { nettyHeaders.add(HttpHeaderNames.TRANSFER_ENCODING, HttpHeaderValues.CHUNKED); } final Object body = message.body(); if (body instanceof NettyCustomizableResponseTypeHandlerInvoker) { NettyCustomizableResponseTypeHandlerInvoker handler = (NettyCustomizableResponseTypeHandlerInvoker) body; handler.invoke(httpRequest, nettyHttpResponse, context); } else { // close handled by HttpServerKeepAliveHandler context.writeAndFlush(nettyResponse); context.read(); } }
if (lastRequest.protocolVersion().isKeepAliveDefault()) { if ("close".equalsIgnoreCase(connection)) { close = true;
@Override public HttpVersion getProtocol() { if (protocol == null) { io.netty.handler.codec.http.HttpVersion version = response .getProtocolVersion(); this.protocol = new HttpVersion(version.protocolName(), version.majorVersion(), version.majorVersion(), version.isKeepAliveDefault()); } return protocol; }
public static boolean keepAlive(HttpHeaders headers, HttpVersion version) { Optional<String> connection = headers.get(CONNECTION); if (connection.isPresent()) { if (CLOSE.toString().equalsIgnoreCase(connection.get())) { return false; } if (KEEP_ALIVE.toString().equalsIgnoreCase(connection.get())) { return true; } } return version.isKeepAliveDefault(); }
private static void writeResponse(final Channel channel, final HttpRequest request, final FullHttpResponse response) { response.headers().set(CONTENT_LENGTH, response.content().readableBytes()); boolean hasKeepAliveHeader = HttpHeaders.equalsIgnoreCase(KEEP_ALIVE, request.headers().get(CONNECTION)); if (!request.getProtocolVersion().isKeepAliveDefault() && hasKeepAliveHeader) { response.headers().set(CONNECTION, KEEP_ALIVE); } final ChannelFuture wf = channel.writeAndFlush(response); if (!HttpHeaders.isKeepAlive(request)) { wf.addListener(ChannelFutureListener.CLOSE); } }
private static void writeResponse(final Channel channel, final HttpRequest request, final FullHttpResponse response) { response.headers().set(CONTENT_LENGTH, response.content().readableBytes()); boolean hasKeepAliveHeader = HttpHeaders.equalsIgnoreCase(KEEP_ALIVE, request.headers().get(CONNECTION)); if (!request.getProtocolVersion().isKeepAliveDefault() && hasKeepAliveHeader) { response.headers().set(CONNECTION, KEEP_ALIVE); } final ChannelFuture wf = channel.writeAndFlush(response); if (!HttpHeaders.isKeepAlive(request)) { wf.addListener(ChannelFutureListener.CLOSE); } }
if (httpVersion.isKeepAliveDefault()) { if (keepAlive) { h.remove(HttpHeaderNames.CONNECTION);
if (httpVersion.isKeepAliveDefault()) { if (keepAlive) { h.remove(HttpHeaderNames.CONNECTION);
if (httpVersion.isKeepAliveDefault()) { if (keepAlive) { h.remove(HttpHeaderNames.CONNECTION);
if (httpVersion.isKeepAliveDefault()) { if (keepAlive) { h.remove(HttpHeaderNames.CONNECTION);
/** * Returns {@code true} if and only if the connection can remain open and * thus 'kept alive'. This methods respects the value of the. * {@code "Connection"} header first and then the return value of * {@link HttpVersion#isKeepAliveDefault()}. */ public static boolean isKeepAlive(HttpMessage message) { CharSequence connection = message.headers().get(HttpHeaderNames.CONNECTION); if (connection != null && HttpHeaderValues.CLOSE.contentEqualsIgnoreCase(connection)) { return false; } if (message.protocolVersion().isKeepAliveDefault()) { return !HttpHeaderValues.CLOSE.contentEqualsIgnoreCase(connection); } else { return HttpHeaderValues.KEEP_ALIVE.contentEqualsIgnoreCase(connection); } }
/** * Returns {@code true} if and only if the connection can remain open and * thus 'kept alive'. This methods respects the value of the. * {@code "Connection"} header first and then the return value of * {@link HttpVersion#isKeepAliveDefault()}. */ public static boolean isKeepAlive(HttpMessage message) { CharSequence connection = message.headers().get(HttpHeaderNames.CONNECTION); if (connection != null && HttpHeaderValues.CLOSE.contentEqualsIgnoreCase(connection)) { return false; } if (message.protocolVersion().isKeepAliveDefault()) { return !HttpHeaderValues.CLOSE.contentEqualsIgnoreCase(connection); } else { return HttpHeaderValues.KEEP_ALIVE.contentEqualsIgnoreCase(connection); } }
/** * Returns {@code true} if and only if the connection can remain open and * thus 'kept alive'. This methods respects the value of the. * * {@code "Connection"} header first and then the return value of * {@link HttpVersion#isKeepAliveDefault()}. */ public static boolean isKeepAlive(HttpMessage message) { CharSequence connection = message.headers().get(HttpHeaderNames.CONNECTION); if (HttpHeaderValues.CLOSE.contentEqualsIgnoreCase(connection)) { return false; } if (message.protocolVersion().isKeepAliveDefault()) { return !HttpHeaderValues.CLOSE.contentEqualsIgnoreCase(connection); } else { return HttpHeaderValues.KEEP_ALIVE.contentEqualsIgnoreCase(connection); } }
/** * Returns {@code true} if and only if the connection can remain open and * thus 'kept alive'. This methods respects the value of the. * {@code "Connection"} header first and then the return value of * {@link HttpVersion#isKeepAliveDefault()}. */ public static boolean isKeepAlive(HttpMessage message) { CharSequence connection = message.headers().get(HttpHeaderNames.CONNECTION); if (connection != null && HttpHeaderValues.CLOSE.contentEqualsIgnoreCase(connection)) { return false; } if (message.protocolVersion().isKeepAliveDefault()) { return !HttpHeaderValues.CLOSE.contentEqualsIgnoreCase(connection); } else { return HttpHeaderValues.KEEP_ALIVE.contentEqualsIgnoreCase(connection); } }
@Override public HttpVersion getProtocol() { if (protocol == null) { io.netty.handler.codec.http.HttpVersion version = response .getProtocolVersion(); this.protocol = new HttpVersion(version.protocolName(), version.majorVersion(), version.majorVersion(), version.isKeepAliveDefault()); } return protocol; }
public static boolean isKeepAlive(HttpServerExchange exchange) { String connection = exchange.getRequestHeaders().get("connection").getFirst(); if (connection != null && HttpHeaderValues.CLOSE.contentEqualsIgnoreCase(connection)) { return false; } else if (toNettyVersion(exchange).isKeepAliveDefault()) { return !HttpHeaderValues.CLOSE.contentEqualsIgnoreCase(connection); } else { return HttpHeaderValues.KEEP_ALIVE.contentEqualsIgnoreCase(connection); } }
if (lastRequest.protocolVersion().isKeepAliveDefault()) { if ("close".equalsIgnoreCase(connection)) { close = true;