Skip to content

Commit

Permalink
Add coverage for HTTP 1.0 request with no host header
Browse files Browse the repository at this point in the history
  • Loading branch information
jedla97 authored and michalvavrik committed Nov 25, 2024
1 parent 122944c commit 6c55951
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6c55951

Please sign in to comment.