Skip to content

feat: add configurable Alt-Svc handler for HTTP/3 alternative service discovery - #2910

Open
Harshal96 wants to merge 4 commits into
vert-x3:masterfrom
Harshal96:feat/alternative-services-handler
Open

Harshal96 wants to merge 4 commits into
vert-x3:masterfrom
Harshal96:feat/alternative-services-handler

Conversation

@Harshal96

Copy link
Copy Markdown
Contributor

Motivation:

Adds a new AltSvcHandler and AltSvcOptions API for advertising HTTP Alternative Services from Vert.x Web routes.

This enables applications to declaratively send Alt-Svc response headers for configured origins, which is useful for HTTP/3 discovery. For example:

router.route().handler(
  AltSvcHandler.create(
    new AltSvcOptions()
      .addOrigin("http://localhost:8080", "h3:localhost:8443")
  )
);

Fixes #2847

@vietj

vietj commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

@Harshal96 thanks for the contribution, the code is missing the support of HTTP/2 that works differently than with a HTTP header, I recommend you read the ALT-SVC RFC to learn more about this. For that matter you should look at HttpServerResponse#writeAltSvc method which has been added for this purpose.

@vietj vietj added this to the 5.2.0 milestone Jun 3, 2026
@Harshal96

Copy link
Copy Markdown
Contributor Author

@vietj done, can you please take a look now?

@Harshal96

Copy link
Copy Markdown
Contributor Author

@vietj is this good for another review?

* Options for configuring {@link AltSvcHandler}.
*/
@DataObject
@JsonGen(publicConverter = false)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we actually don't need JsonGen annotation here, there is no interested in having a converter for this

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

public class AltSvcHandlerImpl implements AltSvcHandler {

private final Map<String, String> origins;
private final Map<HttpConnection, Set<String>> announcedOrigins = new WeakHashMap<>();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we cannot reasonnably maintain such a map because it will never be cleaned from stale connections, so we need to find a way to do that properly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated to remove stale connections

origins = new HashSet<>();
announcedOrigins.put(connection, origins);
// Drop the entry when the connection closes, so the map does not retain stale connections.
connection.closeHandler(v -> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for this we would rather need to develop an HTTP connection local storage instead of relying on the close handler, or actually have a close future for the connection

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

/**
* Storage scoped to the lifetime of an {@link HttpConnection}, without retaining connections after they become unreachable.
*/
public class HttpConnectionLocal<T> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually I meant I would add a map like structure on vertx internal HTTP connection object in vertx-core which would solve the issue more directly

@Harshal96 Harshal96 Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, do you want me to support this in https://github.com/eclipse-vertx/vert.x/tree/master/vertx-core before this can be merged?

@vietj

vietj commented Jul 8, 2026 via email

Copy link
Copy Markdown
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Alternative services handler

2 participants