Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow the 'host' header to be used on HTTP/2 requests if the ':authority' header if missing #5426

Merged
merged 1 commit into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
tsegismont marked this conversation as resolved.
Show resolved Hide resolved
});
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
Loading