This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/main by this push:
new 712854ff03 Correct logic of check- thanks to Han Li
712854ff03 is described below
commit 712854ff0341f94792c7448953780268c7a575e7
Author: Mark Thomas <[email protected]>
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 24f68c7e24..538ed0ba4d 100644
--- a/java/org/apache/coyote/http2/Stream.java
+++ b/java/org/apache/coyote/http2/Stream.java
@@ -472,7 +472,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 3b47dc13ae..eeab280c6b 100644
--- a/test/org/apache/coyote/http2/TestHttp2Section_8_1.java
+++ b/test/org/apache/coyote/http2/TestHttp2Section_8_1.java
@@ -319,6 +319,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();
@@ -344,6 +369,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: [email protected]
For additional commands, e-mail: [email protected]