feat(upgrade): Moved HTTP upgrades off Body to a new API (#2337)

Closes #2086

BREAKING CHANGE: The method `Body::on_upgrade()` is gone. It is
  essentially replaced with `hyper::upgrade::on(msg)`.
This commit is contained in:
Sean McArthur
2020-11-19 16:36:12 -08:00
committed by GitHub
parent 751c122589
commit 121c33132c
6 changed files with 62 additions and 27 deletions

View File

@@ -187,13 +187,15 @@ impl Body {
Body::new(Kind::Wrapped(SyncWrapper::new(Box::pin(mapped))))
}
/// Converts this `Body` into a `Future` of a pending HTTP upgrade.
///
/// See [the `upgrade` module](crate::upgrade) for more.
pub fn on_upgrade(self) -> OnUpgrade {
self.extra
.map(|ex| ex.on_upgrade)
.unwrap_or_else(OnUpgrade::none)
// TODO: Eventually the pending upgrade should be stored in the
// `Extensions`, and all these pieces can be removed. In v0.14, we made
// the breaking changes, so now this TODO can be done without breakage.
pub(crate) fn take_upgrade(&mut self) -> OnUpgrade {
if let Some(ref mut extra) = self.extra {
std::mem::replace(&mut extra.on_upgrade, OnUpgrade::none())
} else {
OnUpgrade::none()
}
}
fn new(kind: Kind) -> Body {