diff --git a/vertx-core/src/main/java/io/vertx/core/http/impl/Http2ServerConnection.java b/vertx-core/src/main/java/io/vertx/core/http/impl/Http2ServerConnection.java index 4bf6918dba3..40ff9ff696f 100644 --- a/vertx-core/src/main/java/io/vertx/core/http/impl/Http2ServerConnection.java +++ b/vertx-core/src/main/java/io/vertx/core/http/impl/Http2ServerConnection.java @@ -136,6 +136,13 @@ private Http2ServerStream createStream(Http2Headers headers, boolean streamEnded authorityHeaderAsString = authorityHeader.toString(); authority = HostAndPort.parseAuthority(authorityHeaderAsString, -1); } + CharSequence hostHeader = null; + if (authority == null) { + hostHeader = headers.getAndRemove(HttpHeaders.HOST); + if (hostHeader != null) { + authority = HostAndPort.parseAuthority(hostHeader.toString(), -1); + } + } CharSequence pathHeader = headers.getAndRemove(HttpHeaders.PSEUDO_PATH); CharSequence methodHeader = headers.getAndRemove(HttpHeaders.PSEUDO_METHOD); return new Http2ServerStream( @@ -143,7 +150,7 @@ private Http2ServerStream createStream(Http2Headers headers, boolean streamEnded streamContextSupplier.get(), headers, schemeHeader != null ? schemeHeader.toString() : null, - authorityHeader != null, + authorityHeader != null || hostHeader != null, authority, methodHeader != null ? HttpMethod.valueOf(methodHeader.toString()) : null, pathHeader != null ? pathHeader.toString() : null, diff --git a/vertx-core/src/test/java/io/vertx/tests/http/Http2ServerTest.java b/vertx-core/src/test/java/io/vertx/tests/http/Http2ServerTest.java index 83f64d5faed..e2fa159777d 100644 --- a/vertx-core/src/test/java/io/vertx/tests/http/Http2ServerTest.java +++ b/vertx-core/src/test/java/io/vertx/tests/http/Http2ServerTest.java @@ -39,6 +39,7 @@ import io.netty.handler.codec.http2.Http2Exception; import io.netty.handler.codec.http2.Http2Flags; import io.netty.handler.codec.http2.Http2FrameAdapter; +import io.netty.handler.codec.http2.Http2FrameListener; import io.netty.handler.codec.http2.Http2Headers; import io.netty.handler.codec.http2.Http2Settings; import io.netty.handler.codec.http2.Http2Stream; @@ -1275,6 +1276,27 @@ public void onPushPromiseRead(ChannelHandlerContext ctx, int streamId, int promi await(); } + @Test + public void testHostHeaderInsteadOfAuthorityPseudoHeader() throws Exception { + // build the HTTP/2 headers, omit the ":authority" pseudo-header and include the "host" header instead + Http2Headers headers = new DefaultHttp2Headers().method("GET").scheme("https").path("/").set("host", DEFAULT_HTTPS_HOST_AND_PORT); + server.requestHandler(req -> { + // validate that the authority is properly populated + assertEquals(DEFAULT_HTTPS_HOST, req.authority().host()); + assertEquals(DEFAULT_HTTPS_PORT, req.authority().port()); + testComplete(); + }); + startServer(); + TestClient client = new TestClient(); + ChannelFuture fut = client.connect(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, request -> { + int id = request.nextStreamId(); + Http2ConnectionEncoder encoder = request.encoder; + encoder.writeHeaders(request.context, id, headers, 0, true, request.context.newPromise()); + }); + fut.sync(); + await(); + } + @Test public void testMissingMethodPseudoHeader() throws Exception { testMalformedRequestHeaders(new DefaultHttp2Headers().scheme("http").path("/"));