Skip to content

Commit

Permalink
HTTP/1.0 requests presenting no host header should be processed and t…
Browse files Browse the repository at this point in the history
…he router should not send back a 400 status response.
  • Loading branch information
vietj committed Aug 30, 2024
1 parent 4446eb5 commit 15ec76a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 50 deletions.
54 changes: 11 additions & 43 deletions vertx-web-api-contract/dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>vertx-web-parent</artifactId>
<groupId>io.vertx</groupId>
<version>4.5.9</version>
<version>4.5.10-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>vertx-web-api-contract</artifactId>
Expand Down Expand Up @@ -50,7 +50,7 @@
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-web</artifactId>
<version>4.5.9</version>
<version>4.5.10-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand All @@ -74,21 +74,21 @@
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-auth-jwt</artifactId>
<version>4.5.9</version>
<version>4.5.10-SNAPSHOT</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-web</artifactId>
<version>4.5.9</version>
<version>4.5.10-SNAPSHOT</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-web-client</artifactId>
<version>4.5.9</version>
<version>4.5.10-SNAPSHOT</version>
<scope>test</scope>
<exclusions>
<exclusion>
Expand All @@ -100,19 +100,19 @@
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-unit</artifactId>
<version>4.5.9</version>
<version>4.5.10-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-auth-properties</artifactId>
<version>4.5.9</version>
<version>4.5.10-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-service-proxy</artifactId>
<version>4.5.9</version>
<version>4.5.10-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -124,13 +124,13 @@
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-core</artifactId>
<version>4.5.9</version>
<version>4.5.10-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-codegen</artifactId>
<version>4.5.9</version>
<version>4.5.10-SNAPSHOT</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
Expand All @@ -155,7 +155,7 @@
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-core</artifactId>
<version>4.5.9</version>
<version>4.5.10-SNAPSHOT</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
Expand Down Expand Up @@ -183,38 +183,6 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-tcnative-boringssl-static</artifactId>
<version>2.0.65.Final</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>netty-tcnative-classes</artifactId>
<groupId>io.netty</groupId>
</exclusion>
<exclusion>
<artifactId>netty-tcnative-boringssl-static</artifactId>
<groupId>io.netty</groupId>
</exclusion>
<exclusion>
<artifactId>netty-tcnative-boringssl-static</artifactId>
<groupId>io.netty</groupId>
</exclusion>
<exclusion>
<artifactId>netty-tcnative-boringssl-static</artifactId>
<groupId>io.netty</groupId>
</exclusion>
<exclusion>
<artifactId>netty-tcnative-boringssl-static</artifactId>
<groupId>io.netty</groupId>
</exclusion>
<exclusion>
<artifactId>netty-tcnative-boringssl-static</artifactId>
<groupId>io.netty</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<properties>
<doc.skip>false</doc.skip>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ private void calculate() {
calculated = true;
remoteAddress = delegate.remoteAddress();
scheme = delegate.scheme();
setHostAndPort(delegate.authority());

HostAndPort authority = delegate.authority();
if (authority != null) {
setHostAndPort(authority);
}

switch (allowForward) {
case X_FORWARD:
Expand All @@ -134,7 +138,7 @@ private void calculate() {
}

if (host != null) {
authority = HostAndPort.create(host, port);
this.authority = HostAndPort.create(host, port);
host = host + (port >= 0 ? ":" + port : "");
absoluteURI = scheme + "://" + host + delegate.uri();
}
Expand Down Expand Up @@ -191,7 +195,7 @@ private void calculateXForward() {
}
}

private void setHostAndPort(HostAndPort authority) {
private void setHostAndPort(HostAndPort authority) {
host = authority.host();
port = authority.port();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public RoutingContextImpl(String mountPoint, RouterImpl router, HttpServerReques
String path = request.path();
HostAndPort authority = request.authority();

if (authority == null || path == null || path.isEmpty()) {
if ((authority == null && request.version() != HttpVersion.HTTP_1_0) || path == null || path.isEmpty()) {
// Authority must be present (HTTP/1.x host header // HTTP/2 :authority pseudo header)
// HTTP paths must start with a '/'
fail(400);
Expand Down
15 changes: 12 additions & 3 deletions vertx-web/src/test/java/io/vertx/ext/web/RouterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2601,11 +2601,20 @@ public void testRoutePathNoSlashBegin() throws Exception {
}

@Test
public void testMissingHostHeader() throws Exception {
public void testMissingHostHeaderHttp1_1() throws Exception {
testMissingHostHeader("HTTP/1.1", 400);
}

@Test
public void testMissingHostHeaderHttp1_0() throws Exception {
testMissingHostHeader("HTTP/1.0", 200);
}

private void testMissingHostHeader(String httpVersion, int expectedStatusCode) throws Exception {
router.route().handler(rc -> rc.response().end());
NetClient nc = vertx.createNetClient();
nc.connect(SocketAddress.inetSocketAddress(8080, "localhost")).onComplete(onSuccess(so -> {
so.write("GET / HTTP/1.1\r\n\r\n");
so.write("GET / " + httpVersion + "\r\n\r\n");
Buffer response = Buffer.buffer();
so.handler(chunk -> {
response.appendBuffer(chunk);
Expand All @@ -2615,7 +2624,7 @@ public void testMissingHostHeader() throws Exception {
so.handler(null);
String[] line = s.substring(0, idx).split("\\s+");
assertTrue(line.length >= 3);
assertEquals("400", line[1]);
assertEquals("" + expectedStatusCode, line[1]);
testComplete();
}
});
Expand Down

0 comments on commit 15ec76a

Please sign in to comment.