From e95ce2c2fc41cb454dbcbd32ddec67f148f2285e Mon Sep 17 00:00:00 2001 From: Oleg Kalnichevski Date: Sat, 12 Oct 2024 15:22:39 +0200 Subject: [PATCH] Bug fix: allow `Host` headers in HTTP/2 request messages --- .../core5/http2/protocol/H2RequestConformance.java | 1 - .../core5/http2/protocol/TestH2Interceptors.java | 4 ++-- .../compatibility/http2/ApacheHttpDCompatIT.java | 14 -------------- 3 files changed, 2 insertions(+), 17 deletions(-) diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/protocol/H2RequestConformance.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/protocol/H2RequestConformance.java index a2d010b14..ef528fbc2 100644 --- a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/protocol/H2RequestConformance.java +++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/protocol/H2RequestConformance.java @@ -67,7 +67,6 @@ public H2RequestConformance() { HttpHeaders.KEEP_ALIVE, HttpHeaders.PROXY_CONNECTION, HttpHeaders.TRANSFER_ENCODING, - HttpHeaders.HOST, HttpHeaders.UPGRADE, HttpHeaders.TE); } diff --git a/httpcore5-h2/src/test/java/org/apache/hc/core5/http2/protocol/TestH2Interceptors.java b/httpcore5-h2/src/test/java/org/apache/hc/core5/http2/protocol/TestH2Interceptors.java index ef2e84aaa..38410c787 100644 --- a/httpcore5-h2/src/test/java/org/apache/hc/core5/http2/protocol/TestH2Interceptors.java +++ b/httpcore5-h2/src/test/java/org/apache/hc/core5/http2/protocol/TestH2Interceptors.java @@ -194,8 +194,8 @@ void testH2RequestConformanceHostHeader() { request.addHeader("Host", "host"); final H2RequestConformance interceptor = new H2RequestConformance(); - Assertions.assertThrows(HttpException.class, () -> interceptor.process(request, null, context), - "Header 'Host: host' is illegal for HTTP/2 messages"); + Assertions.assertDoesNotThrow(() -> interceptor.process(request, null, context), + "Header 'Host: host' is permissible for HTTP/2 messages"); } @Test diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/compatibility/http2/ApacheHttpDCompatIT.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/compatibility/http2/ApacheHttpDCompatIT.java index 55ce9cea2..0277dba0a 100644 --- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/compatibility/http2/ApacheHttpDCompatIT.java +++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/compatibility/http2/ApacheHttpDCompatIT.java @@ -27,11 +27,8 @@ package org.apache.hc.core5.testing.compatibility.http2; -import org.apache.hc.core5.http.HttpHeaders; import org.apache.hc.core5.http.HttpHost; -import org.apache.hc.core5.http2.impl.H2Processors; import org.apache.hc.core5.http2.impl.nio.bootstrap.H2RequesterBootstrap; -import org.apache.hc.core5.http2.protocol.H2RequestConformance; import org.apache.hc.core5.testing.compatibility.ContainerImages; import org.junit.jupiter.api.AfterAll; import org.testcontainers.containers.GenericContainer; @@ -46,17 +43,6 @@ class ApacheHttpDCompatIT extends AbstractHttp2CompatIT { @Override void configure(final H2RequesterBootstrap bootstrap) { - bootstrap.setHttpProcessor(H2Processors.customClient(null) - .addFirst(new H2RequestConformance( - HttpHeaders.CONNECTION, - HttpHeaders.KEEP_ALIVE, - HttpHeaders.PROXY_CONNECTION, - HttpHeaders.TRANSFER_ENCODING, -// For some reason Apache HTTPD includes Host header in HTTP/2 promise messages -// though it should not -// HttpHeaders.HOST, - HttpHeaders.UPGRADE)) - .build()); } HttpHost targetHost() {