4.x: Make HttpRouting an interface #8572
Labels
4.x
Version 4.x
design
This issue requires design/architecture decisions
enhancement
New feature or request
P3
webserver
Environment Details
Problem Description
This is more of an improvement proposal but does address an actual issue as well (though probably not one that people will encounter in practice). Currently
HttpRoute
is an interface, whereasHttpRouting
isn't (it's a final class). It would be good to be consistent and make both interfaces, as it allows for more configurability, and almost everything else that can be specified in aWebServer
builder is an interface.Use Case
Being able to implement your own
HttpRouting
type can be useful when moving an existing service to Helidon; for example if there already is custom routing logic for it.Issue to Solve Along the Way
As for the actual issue (one might call it a bug) I encountered while working on this: other routing classes (such as
GrpcRouting
) aren't final, which one might understand as Helidon supporting custom implementations. However, if one does so, requests aren't properly routed anymore. The reason for this is that theRouterImpl
indexesRouting
instances by their class and itsrouting
method is always called with a fixed class. Therefore, when trying to use a custom implementation, it wouldn't be found.This issue needs to be addressed if one wants to make
HttpRouting
an interface. As a side-effect it would fix the "bug" just described, allowing theRouterImpl
to handle custom implementations of other routing types.Compatibility
This change should be (mostly) backwards compatible. Currently, the
HttpRouting
class is final (so no existing code can break because it subclassesHttpRouting
) and its constructor is private (so no existing code can break because the constructor won't exist anymore).Other Considerations
Even with
HttpRouting
becoming an interface, it wouldn't be straightforward to use a custom implementation. TheWebServer.Builder.routing
method takes aHttpRouting.Builder
; providing aHttpRouting
instance directly isn't possible. So, to use a custom routing implementation, one would also have to also create a customHttpRouting.Builder
, whosebuild
method returns an instance of the custom routing implementation. This isn't great but also not a big deal as most users won't be doing this. Anyway, improving this is out of scope of this issue.The text was updated successfully, but these errors were encountered: