Skip to content

Commit

Permalink
allow the 'host' header to be used on HTTP/2 requests if the ':author…
Browse files Browse the repository at this point in the history
…ity' header if missing

see eclipse-vertx#5425

Signed-off-by: Jesse White <[email protected]>
  • Loading branch information
j-white committed Dec 20, 2024
1 parent b0c9721 commit 56710f7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,21 @@ 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(
this,
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,
Expand Down
22 changes: 22 additions & 0 deletions src/test/java/io/vertx/core/http/Http2ServerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1278,6 +1279,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("/"));
Expand Down

0 comments on commit 56710f7

Please sign in to comment.