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

Setting :authority with HTTP2 transport #11923

Closed
moscicky opened this issue Jun 14, 2024 · 2 comments
Closed

Setting :authority with HTTP2 transport #11923

moscicky opened this issue Jun 14, 2024 · 2 comments
Labels

Comments

@moscicky
Copy link

Jetty Version
12

Jetty Environment
core

Java Version
17

Question
In #5633 a support for setting :authority header with HttpClient was introduced. The original issue mentions a fluent builder liker API (authority()) for a Request but the linked PR is using sth called HTTPDestination.

Could you point me to a piece of docs or guide me how to properly use the API? Say I am sending an HTTP2 request to an Envoy proxy running on localhost:5000 and want to include :authority header set to: foo.bar.baz

@joakime
Copy link
Contributor

joakime commented Jun 14, 2024

The Jetty 12 version of the same testcase is ...

@ParameterizedTest
@MethodSource("transports")
public void testRequestWithDifferentDestination(Transport transport) throws Exception
{
String requestScheme = newURI(transport).getScheme();
String requestHost = "otherHost.com";
int requestPort = 8888;
start(transport, new Handler.Abstract()
{
@Override
public boolean handle(Request request, org.eclipse.jetty.server.Response response, Callback callback)
{
HttpURI uri = request.getHttpURI();
assertEquals(requestHost, uri.getHost());
assertEquals(requestPort, uri.getPort());
if (transport == Transport.H2C || transport == Transport.H2)
assertEquals(requestScheme, uri.getScheme());
callback.succeeded();
return true;
}
});
if (transport.isSecure())
httpConfig.getCustomizer(SecureRequestCustomizer.class).setSniHostCheck(false);
Origin origin = new Origin(requestScheme, "localhost", ((NetworkConnector)connector).getLocalPort());
Destination destination = client.resolveDestination(origin);
var request = client.newRequest(requestHost, requestPort)
.scheme(requestScheme)
.path("/path");
CountDownLatch resultLatch = new CountDownLatch(1);
destination.send(request, result ->
{
assertTrue(result.isSucceeded());
assertEquals(HttpStatus.OK_200, result.getResponse().getStatus());
resultLatch.countDown();
});
assertTrue(resultLatch.await(5, TimeUnit.SECONDS));
}

What's the key piece of information is ...

// Setup the destination to physically connect to.
Origin origin = new Origin(scheme, destHost, destPort);
Destination destination = client.resolveDestination(origin);

// What the HTTP request should contain for Authority
var request = client.newRequest(requestHost, requestPort)
    .scheme(requestScheme)
    .path("/path");

// Initiate the request to the specified destination.
destination.send(request, result -> {
    // process the results
});

@moscicky
Copy link
Author

Great, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants