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 #5425

Signed-off-by: Jesse White <[email protected]>
  • Loading branch information
j-white committed Dec 19, 2024
1 parent b0c9721 commit b5614d9
Show file tree
Hide file tree
Showing 2 changed files with 29 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
21 changes: 21 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,26 @@ public void onPushPromiseRead(ChannelHandlerContext ctx, int streamId, int promi
await();
}

@Test
public void testHostHeaderInsteadOfAuthorityPseudoHeader() throws Exception {
testValidRequestHeaders(new DefaultHttp2Headers().method("GET").scheme("https").path("/").set("host", DEFAULT_HTTPS_HOST_AND_PORT));
}

private void testValidRequestHeaders(Http2Headers headers) throws Exception {
server.requestHandler(req -> {
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 b5614d9

Please sign in to comment.