diff --git a/modules/transport-netty4/src/internalClusterTest/java/org/opensearch/http/netty4/Netty4BlockingPlugin.java b/modules/transport-netty4/src/internalClusterTest/java/org/opensearch/http/netty4/Netty4BlockingPlugin.java index 853ea34eb7fbc..0acf3e50325c7 100644 --- a/modules/transport-netty4/src/internalClusterTest/java/org/opensearch/http/netty4/Netty4BlockingPlugin.java +++ b/modules/transport-netty4/src/internalClusterTest/java/org/opensearch/http/netty4/Netty4BlockingPlugin.java @@ -32,15 +32,10 @@ import io.netty.handler.codec.http.FullHttpResponse; import io.netty.handler.codec.http.HttpRequest; import io.netty.handler.codec.http.HttpResponseStatus; -import io.netty.handler.codec.http.HttpVersion; import io.netty.util.ReferenceCountUtil; public class Netty4BlockingPlugin extends Netty4ModulePlugin { - public Netty4BlockingPlugin() { - super(); - } - public class Netty4BlockingHttpServerTransport extends Netty4HttpServerTransport { public Netty4BlockingHttpServerTransport( @@ -109,11 +104,12 @@ public class ExampleBlockingNetty4HeaderVerifier extends ChannelInboundHandlerAd public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (!(msg instanceof HttpRequest)) { ctx.fireChannelRead(msg); + return; } HttpRequest request = (HttpRequest) msg; if (!isAuthenticated(request)) { - final FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.UNAUTHORIZED); + final FullHttpResponse response = new DefaultFullHttpResponse(request.protocolVersion(), HttpResponseStatus.UNAUTHORIZED); ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE); ReferenceCountUtil.release(msg); } else { diff --git a/modules/transport-netty4/src/internalClusterTest/java/org/opensearch/http/netty4/Netty4HeaderVerifierIT.java b/modules/transport-netty4/src/internalClusterTest/java/org/opensearch/http/netty4/Netty4HeaderVerifierIT.java index e4437761851af..33af5ed185b12 100644 --- a/modules/transport-netty4/src/internalClusterTest/java/org/opensearch/http/netty4/Netty4HeaderVerifierIT.java +++ b/modules/transport-netty4/src/internalClusterTest/java/org/opensearch/http/netty4/Netty4HeaderVerifierIT.java @@ -52,14 +52,15 @@ public void testThatNettyHttpServerRequestBlockedWithHeaderVerifier() throws Exc final FullHttpRequest blockedRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/"); blockedRequest.headers().add("blockme", "Not Allowed"); blockedRequest.headers().add(HOST, "localhost"); - blockedRequest.headers().add("scheme", "http"); final List responses = new ArrayList<>(); - try (Netty4HttpClient nettyHttpClient = Netty4HttpClient.http2()) { + try (Netty4HttpClient nettyHttpClient = Netty4HttpClient.http()) { try { FullHttpResponse blockedResponse = nettyHttpClient.send(transportAddress.address(), blockedRequest); responses.add(blockedResponse); assertThat(blockedResponse.status().code(), equalTo(401)); + } catch (Exception e) { + e.printStackTrace(); } finally { responses.forEach(ReferenceCounted::release); }