Fix connection keep-alive header handling
This commit fixes an issue with the handling of the value "keep-alive" on the Connection header in the Netty 4 HTTP implementation while handling an HTTP 1.0 request. The issue was using the wrong equals method to compare an AsciiString instance and a String instance (they could never be equal). This commit fixes this to use the correct equals method to compare for content equality.
This commit is contained in:
parent
cd5777593a
commit
c1bdaaf80f
|
@ -186,7 +186,7 @@ final class Netty4HttpChannel extends AbstractRestChannel {
|
|||
private boolean isCloseConnection() {
|
||||
final boolean http10 = isHttp10();
|
||||
return HttpHeaderValues.CLOSE.contentEqualsIgnoreCase(nettyRequest.headers().get(HttpHeaderNames.CONNECTION)) ||
|
||||
(http10 && HttpHeaderValues.KEEP_ALIVE.equals(nettyRequest.headers().get(HttpHeaderNames.CONNECTION)) == false);
|
||||
(http10 && !HttpHeaderValues.KEEP_ALIVE.contentEqualsIgnoreCase(nettyRequest.headers().get(HttpHeaderNames.CONNECTION)));
|
||||
}
|
||||
|
||||
// Create a new {@link HttpResponse} to transmit the response for the netty request.
|
||||
|
|
|
@ -219,18 +219,29 @@ public class Netty4HttpChannelTests extends ESTestCase {
|
|||
try (Netty4HttpServerTransport httpServerTransport =
|
||||
new Netty4HttpServerTransport(settings, networkService, bigArrays, threadPool)) {
|
||||
httpServerTransport.start();
|
||||
final FullHttpRequest httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/");
|
||||
httpRequest.headers().add(HttpHeaderNames.CONNECTION, HttpHeaderValues.CLOSE);
|
||||
final FullHttpRequest httpRequest;
|
||||
final boolean close = randomBoolean();
|
||||
if (randomBoolean()) {
|
||||
httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/");
|
||||
if (close) {
|
||||
httpRequest.headers().add(HttpHeaderNames.CONNECTION, HttpHeaderValues.CLOSE);
|
||||
}
|
||||
} else {
|
||||
httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_0, HttpMethod.GET, "/");
|
||||
if (!close) {
|
||||
httpRequest.headers().add(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE);
|
||||
}
|
||||
}
|
||||
final EmbeddedChannel embeddedChannel = new EmbeddedChannel();
|
||||
final Netty4HttpRequest request = new Netty4HttpRequest(httpRequest, embeddedChannel);
|
||||
|
||||
// send a response, the channel should close
|
||||
// send a response, the channel close status should match
|
||||
assertTrue(embeddedChannel.isOpen());
|
||||
final Netty4HttpChannel channel =
|
||||
new Netty4HttpChannel(httpServerTransport, request, null, randomBoolean(), threadPool.getThreadContext());
|
||||
final TestResponse resp = new TestResponse();
|
||||
channel.sendResponse(resp);
|
||||
assertFalse(embeddedChannel.isOpen());
|
||||
assertThat(embeddedChannel.isOpen(), equalTo(!close));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue