-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
A hyper without tokio-proto #1342
Comments
(aside)
@seanmonstar is there any discussion to read on this? |
@kamalmarhubi tokio-rs/tokio-rfcs#3 has some background. |
cc @alexcrichton @withoutboats Glad to see things heading this way -- please let me know if we can be of any help. |
@aturon I'd certainly welcome any thoughts around the API. Pulling out some questions:
|
I'd like to help work on this, but I would feel like I have a better sense of how everything should fit together once some of our work on h2 and other surrounding libs start to stabilize. That said, it is good to start writing this down. |
For now, this adds `client::Config::no_proto`, `server::Http::no_proto`, and `server::Server::no_proto` to skip tokio-proto implementations, and use an internal dispatch system instead. `Http::no_proto` is similar to `Http::bind_connection`, but returns a `Connection` that is a `Future` to drive HTTP with the provided service. Any errors prior to parsing a request, and after delivering a response (but before flush the response body) will be returned from this future. See #1342 for more.
For now, this adds `client::Config::no_proto`, `server::Http::no_proto`, and `server::Server::no_proto` to skip tokio-proto implementations, and use an internal dispatch system instead. `Http::no_proto` is similar to `Http::bind_connection`, but returns a `Connection` that is a `Future` to drive HTTP with the provided service. Any errors prior to parsing a request, and after delivering a response (but before flush the response body) will be returned from this future. See #1342 for more.
For now, this adds `client::Config::no_proto`, `server::Http::no_proto`, and `server::Server::no_proto` to skip tokio-proto implementations, and use an internal dispatch system instead. `Http::no_proto` is similar to `Http::bind_connection`, but returns a `Connection` that is a `Future` to drive HTTP with the provided service. Any errors prior to parsing a request, and after delivering a response (but before flush the response body) will be returned from this future. See #1342 for more.
For now, this adds `client::Config::no_proto`, `server::Http::no_proto`, and `server::Server::no_proto` to skip tokio-proto implementations, and use an internal dispatch system instead. `Http::no_proto` is similar to `Http::bind_connection`, but returns a `Connection` that is a `Future` to drive HTTP with the provided service. Any errors prior to parsing a request, and after delivering a response (but before flush the response body) will be returned from this future. See #1342 for more.
#1362 is available, which starts to address this. Specifically, it adds a configuration option to disable the tokio-proto usage in the server and client. It is not enabled by default, until some more testing shows that at least it has fewer bugs than the tokio-proto dispatch does. Once determined it should be the default, the The work in #1362 already has some benefits:
|
For now, this adds `client::Config::no_proto`, `server::Http::no_proto`, and `server::Server::no_proto` to skip tokio-proto implementations, and use an internal dispatch system instead. `Http::no_proto` is similar to `Http::bind_connection`, but returns a `Connection` that is a `Future` to drive HTTP with the provided service. Any errors prior to parsing a request, and after delivering a response (but before flush the response body) will be returned from this future. See #1342 for more.
For now, this adds `client::Config::no_proto`, `server::Http::no_proto`, and `server::Server::no_proto` to skip tokio-proto implementations, and use an internal dispatch system instead. `Http::no_proto` is similar to `Http::bind_connection`, but returns a `Connection` that is a `Future` to drive HTTP with the provided service. Any errors prior to parsing a request, and after delivering a response (but before flush the response body) will be returned from this future. See #1342 for more.
An update: starting in v0.11.11, the new dispatcher was set to be enabled by default, and the tokio-proto specific parts were deprecated.
|
@seanmonstar: Do you have any idea how hard it will be to migrate Hyper + rustls to the new API? |
There is a new |
It would be nice to have hyper working without internally using tokio-proto. It should be possible to do this in a backwards-compatible way at first, such that the server still provides a
ServerProto
implementation that makes use of the internal stuff, and that can be deprecated in the future.Motivation
Stream
Expect: 100-continue
(Change 100-continue behavior to send when Body has been polled #838)API
Http::bind_connection(socket, service) -> Connection
Compared to the current
bind_connection
:socket
isT: AsyncRead + AsyncWrite
.service
is currently aS: Service
.addr
is not needed anymore. Anyone wanting to know the address can store it on theirService
.handle
is not provided, since it's only purpose was to spawn a task on it. With the desire to separate tokio from being a task executor, we can plan ahead.The returned type is a
Connection<T, S>
, which implementsFuture
. Instead of taking aHandle
, a user can instead receive this future and spawn it on any executor they desire.Of course, since
bind_connection
already exist, this would need a new name. It could bebind_connection2
, with the previous deprecated, with the intent to finish the replacement in 0.12.Or maybe
bind_connection
itself isn't the best of names. The action of this method is to apply theHttp
protocol to a connection, aided by theService
to respond to requests.Connection
This is returned by
Http::bind_connection
, and implementsFuture
.Item = ()
Error = hyper::Error
If there are never any errors when processing the connection, the future yields
Ok(Async::Ready)
whenHttp
says it should close.If there are errors encountered that would require tearing down the connection, the future returns the
Err
. Importantly, this allows users to very easily know if there was an error reading or writing the HTTP protocol.Some unresolved questions:
Item
be the socket (T
) instead, in case there is desire to be able to do something with the socket after HTTP is "done" (perhaps due to a protocol upgrade).Connection
future, as it should keep working.Connection
shouldn't be aFuture
directly, but more like aStream
... ofErr
s...Connection
could alternatively grow aon_stream_error<F>(callback: F)
whereF: Fn(hyper::Error)
or something...Server
The current
Server
type is supposed to be an "easy mode" for starting up a TCP listener and accepting plain text HTTP requests. There is a related proposal (#1322) to makeServer
accept any kind of listener, and be aFuture
so users can execute it with their own executor.Perhaps that proposal should be updated to support this new
Connection
future:impl Stream for Server
instead ofFuture
.Server
could be aStream
of already boundConnection
s.Server
to automatically callHttp::bind_connection
with a service, and manage graceful shutdown, while still being able to watch for errors that happen in that connection.We could add some convenience methods to
Server
, likerun_ignore_errors() -> impl Future
, so a user could easily just "run" the server without worrying about it being aStream
ofConnection
s.Usage
Bare bones
bind_connection
Fuller example with a tokio
Core
and hyperServer
Meta unresolved questions
Http
is more like aServerBuilder
orConnectionBuilder
...Http
were named a builder,Http
could replaceConnection
? Such thatServer
is aStream<Item=Http>
?Server
type, but hyper currently asks you to grab theHttp
to configure aServer
.The text was updated successfully, but these errors were encountered: