From 6c55951fcf3f36acd17482f31fcfe1bf0dee903d Mon Sep 17 00:00:00 2001 From: Jakub Jedlicka Date: Mon, 25 Nov 2024 09:05:00 +0100 Subject: [PATCH] Add coverage for HTTP 1.0 request with no host header --- .../ts/http/advanced/reactive/HeadersIT.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/http/http-advanced-reactive/src/test/java/io/quarkus/ts/http/advanced/reactive/HeadersIT.java b/http/http-advanced-reactive/src/test/java/io/quarkus/ts/http/advanced/reactive/HeadersIT.java index 1633ec1a6..c7c99c949 100644 --- a/http/http-advanced-reactive/src/test/java/io/quarkus/ts/http/advanced/reactive/HeadersIT.java +++ b/http/http-advanced-reactive/src/test/java/io/quarkus/ts/http/advanced/reactive/HeadersIT.java @@ -7,7 +7,13 @@ import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.stringContainsInOrder; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.net.Socket; import java.util.List; import org.junit.jupiter.api.Tag; @@ -16,6 +22,7 @@ import io.quarkus.test.bootstrap.RestService; import io.quarkus.test.scenarios.QuarkusScenario; import io.quarkus.test.services.QuarkusApplication; +import io.quarkus.test.services.URILike; import io.restassured.http.Header; import io.restassured.response.ValidatableResponse; @@ -116,6 +123,27 @@ void testWithNoAcceptHeader() { .body(is("Headers response: ok headers")); } + @Test + @Tag("https://github.com/quarkusio/quarkus/discussions/42636") + public void testHttp10WithoutHostHeader() throws InterruptedException, IOException { + // We can't use java client as it's always adding `\r\n` to the host header. + URILike uri = app.getURI(); + StringBuilder response = new StringBuilder(); + try (Socket s = new Socket(uri.getHost(), uri.getPort()); + PrintWriter pw = new PrintWriter(s.getOutputStream()); + BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));) { + pw.print("GET /headers/any HTTP/1.0\n\r\n"); + pw.flush(); + String line; + while ((line = br.readLine()) != null) { + response.append(line).append("/n"); + } + } + + assertThat(response.toString(), stringContainsInOrder("HTTP/1.0", "200 OK")); + app.logs().assertDoesNotContain("Unhandled exception in router"); + } + /** * Cache-Control header may be present multiple times in the response, e.g. in an OpenShift deployment. That is why we need * to look for a specific value among all headers of the same name, and not just match the last one of them, which is what