-
Notifications
You must be signed in to change notification settings - Fork 173
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
feat(http server): add new builder APIs build_from_tcp
and build_from_hyper
#719
Conversation
Ooh offhand this looks very neat, I like it! I also like that it removes socket2 as a dependency and leaves it to the user to provide their own socket thing (if I read it right)! |
yeah, you are right and that is the idea :) AFAIK, most socket libraries implements |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Loooks good to me; I really like letting somebody provide (and configure) their own socket rather than handling it internally :)
The hyper settings might contradict to settings on the provided socket, force users of this API to configure that avoid confusion and unexpected settings.
http-server/src/server.rs
Outdated
/// let server = HttpServerBuilder::new().build_from_tcp(socket, hyper_cfg).unwrap(); | ||
/// } | ||
/// ``` | ||
pub fn build_from_tcp(self, listener: impl Into<StdTcpListener>, cfg: HyperTcpConfig) -> Result<Server<M>, Error> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jsdw is this API reasonable?
Basically the only thing I want to ensure is that no settings gets overwritten without informing the users of this API.
It's a bit awkward to configure some settings twice but no way around that....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aah ok, so the issue is now basically that you can pass in a TcpListener
, but you can't configure the Hyper
server that is created from it.
One option might be to keep build_from_tcp()
as is (which lets you pass in a pre-configured tcp listener but assumes you don't care about how the resulting hyper server is configured), and also have a build_from_hyper()
as well (which lets you control everything about the tcp listener and hyper server if you wish). So then you'd have:
build
-> can't configure socket, can't configure hyper.build_from_tcp
-> can configure tcp socket, can't configure hyper.build_from_hyper
-> can configure tcp, can configure hyper.
What do you reckon?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fair enough, I think your suggestion is less awkward.
…' into na-tcp-socket-configurations-api
build_from_tcp
and build_from_hyper
build_from_tcp
and build_from_hyper
build_from_tcp
and build_from_hyper
Before the HTTP server configured the socket explictly but this PR changes to use
tokio::net::TcpListener
similar to what theWsServer does
In addition this PR adds another API for users to provide their own TcpListener, see the inline example I added with socket2.
Example: