Make serve generic over the HTTP implementations #3484
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
Currently, only serving with hyper with predefined configuration is supported out of the box. This runs into issues where people want to configure hyper settings (#3305, #2980, #2939). It's fairly complicated to use anything but the default hyper setup, though it is of course possible even now as shown in several low-level examples.
I see this as the natural extension of #2941. We can allow
serve
to not only be generic over the way connections are accepted, but also how they're handled before aRequest
is created for our router to handle (and how to handle the returnedResponse
).Solution
This adds a
ConnectionBuilder
trait that receives anIo
andService
and connects them to an underlying logic that handles HTTP, e.g. a hyper connection.The current implementation adds
hyper-util
as a public dependency which might not be desirable, in which case we may want to not expose the constructor withBuilder
, and have a 3rd party crate likeaxum-server
create something like this with exposed internals. That would go a bit against the issues listed in motivation, but even with that, I think it would be nicer to expose hyper-specific settings this way as well as letting others to build customConnectionBuilder
s without having to copy the wholeserve
implementation from here.I've also added two examples. One is TLS usage with otherwise the default hyper implementation and the other is for showcasing using something else than hyper, in this case Rama.