Add higher-level HTTP upgrade support to Client and Server#1563
Merged
seanmonstar merged 1 commit intomasterfrom Jun 14, 2018
Merged
Add higher-level HTTP upgrade support to Client and Server#1563seanmonstar merged 1 commit intomasterfrom
seanmonstar merged 1 commit intomasterfrom
Conversation
47a3338 to
364c37e
Compare
- Adds `Body::on_upgrade()` that returns an `OnUpgrade` future.
- Adds `hyper::upgrade` module containing types for dealing with
upgrades.
- Adds `server::conn::Connection::with_upgrades()` method to enable
these upgrades when using lower-level API (because of a missing
`Send` bound on the transport generic).
- Client connections are automatically enabled.
- Optimizes request parsing, to make up for extra work to look for
upgrade requests.
- Returns a smaller `DecodedLength` type instead of the fatter
`Decoder`, which should also allow a couple fewer branches.
- Removes the `Decode::Ignore` wrapper enum, and instead ignoring
1xx responses is handled directly in the response parsing code.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This proposes a way to offer an easier way to manage HTTP upgrades than using the lower-level
client::connandserver::connAPIs. This includes bothUpgrade+101 Switching Protocols, andCONNECTtunneling.Body::on_upgradeIt makes use of the
Bodytype that is returned by hyper. When the HTTP1 state machine notices an attempt to trigger an upgrade in either the client or the server, the returnedBodywill have some additional state to allow getting aFutureof an eventual upgrade:Body::on_upgrade(self) -> impl Future.This
on_upgradefuture, if successful, will return a newhyper::upgrade::Upgradedtype that fully owns the original IO transport, after the upgrade. TheUpgradedcan itself be used as anAsyncRead/AsyncWritefor convenience (and automatically including any buffered bytes as part of thereads). However, if desired, you can also try to deconstruct/downcast from anUpgradedintohyper::upgrade::Parts<T>.hyper::upgrade::UpgradedAn added benefit to this API is that it allows adding support for
CONNECTover HTTP2 without breaking backwards compatibility. The tricky part there normally is thatCONNECTin HTTP2 doesn't actually take control of the IO transport, but instead continues to sendDATAframes over the h2 stream. So, once theh2library adds support, hyper can encapsulate that support in a privateimpl AsyncRead + AsyncWriteimplementation, and still just return anUpgraded.A papercut in the proposal is that
Upgradedneeds to put the IO in a trait object that can be putBody, which isSend. There was a missingI: Sendbounds onserver::conn::Connection, which makes it impossible to use this new API when using the lower-levelHttp::server_connection. The proposed solution is to addConnection::with_upgrades()that converts into a type that does have aSendbound, and allows using this API.Any usage of
serve_connectionthat forgets to addwith_upgradeswill not have upgrades work. Theon_upgradefuture will yield anError. This error however, does include specific messaging when an upgrade was expected to work, but couldn't because of use of lower-level APIs. Additionally, this means that manual upgrades with the lower-level APIs still work correctly.TODO
hyper::upgrademodule.server::conn::Connection::with_upgradesmethod.Closes #1395