This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 9.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/9.0.x by this push: new f88c2e13b4 Correct logic of check- thanks to Han Li f88c2e13b4 is described below commit f88c2e13b484c4bd7a2667a31f41a74adfa3d25d Author: Mark Thomas <ma...@apache.org> AuthorDate: Mon Aug 8 15:03:09 2022 +0100 Correct logic of check- thanks to Han Li --- java/org/apache/coyote/http2/Stream.java | 2 +- .../apache/coyote/http2/TestHttp2Section_8_1.java | 50 ++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/java/org/apache/coyote/http2/Stream.java b/java/org/apache/coyote/http2/Stream.java index b9a2f77f12..3cdcb547e4 100644 --- a/java/org/apache/coyote/http2/Stream.java +++ b/java/org/apache/coyote/http2/Stream.java @@ -467,7 +467,7 @@ class Stream extends AbstractNonZeroStream implements HeaderEmitter { throw new HpackException(sm.getString("stream.header.invalid", getConnectionId(), getIdAsString(), "host", value)); } - if (i == -1 && value.equals(coyoteRequest.serverName().getString()) || + if (i == -1 && !value.equals(coyoteRequest.serverName().getString()) || i > -1 && ((!value.substring(0, i).equals(coyoteRequest.serverName().getString()) || Integer.parseInt(value.substring(i + 1)) != coyoteRequest.getServerPort()))) { // Host value inconsistent diff --git a/test/org/apache/coyote/http2/TestHttp2Section_8_1.java b/test/org/apache/coyote/http2/TestHttp2Section_8_1.java index ef57e98cef..779d308cd0 100644 --- a/test/org/apache/coyote/http2/TestHttp2Section_8_1.java +++ b/test/org/apache/coyote/http2/TestHttp2Section_8_1.java @@ -318,6 +318,31 @@ public class TestHttp2Section_8_1 extends Http2TestBase { } + @Test + public void testHostHeaderConsistentNoPort() throws Exception { + http2Connect(); + + List<Header> headers = new ArrayList<>(4); + headers.add(new Header(":method", "GET")); + headers.add(new Header(":scheme", "http")); + headers.add(new Header(":authority", "localhost")); + headers.add(new Header(":path", "/simple")); + headers.add(new Header("host", "localhost")); + + byte[] headersFrameHeader = new byte[9]; + ByteBuffer headersPayload = ByteBuffer.allocate(128); + + buildGetRequest(headersFrameHeader, headersPayload, null, headers , 3); + + writeFrame(headersFrameHeader, headersPayload); + + parser.readFrame(true); + + String trace = output.getTrace(); + Assert.assertTrue(trace, trace.contains("3-Header-[:status]-[200]")); + } + + @Test public void testHostHeaderInconsistent() throws Exception { http2Connect(); @@ -343,6 +368,31 @@ public class TestHttp2Section_8_1 extends Http2TestBase { } + @Test + public void testHostHeaderInconsistentNoPort() throws Exception { + http2Connect(); + + List<Header> headers = new ArrayList<>(4); + headers.add(new Header(":method", "GET")); + headers.add(new Header(":scheme", "http")); + headers.add(new Header(":authority", "localhost")); + headers.add(new Header(":path", "/simple")); + headers.add(new Header("host", "otherhost")); + + byte[] headersFrameHeader = new byte[9]; + ByteBuffer headersPayload = ByteBuffer.allocate(128); + + buildGetRequest(headersFrameHeader, headersPayload, null, headers , 3); + + writeFrame(headersFrameHeader, headersPayload); + + parser.readFrame(true); + + String trace = output.getTrace(); + Assert.assertTrue(trace, trace.contains("0-Goaway-[1]-[9]")); + } + + private void doInvalidPseudoHeaderTest(List<Header> headers) throws Exception { http2Connect(); --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org