Skip to content

Commit

Permalink
feat(lib): update to http 1.0
Browse files Browse the repository at this point in the history
Updates dependencies `http` and `http-body` to 1.0.

To do so, implements `Clone` for `OnUpgrade`.

BREAKING CHANGE: Upgrade to `http` 1.0.
  • Loading branch information
seanmonstar committed Nov 15, 2023
1 parent 6fd696e commit d98c9e5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ include = [
bytes = "1"
futures-channel = "0.3"
futures-util = { version = "0.3", default-features = false }
http = "0.2.7"
http-body = "=1.0.0-rc.2"
http = "1"
http-body = "1"
pin-project-lite = "0.2.4"
tokio = { version = "1.13", features = ["sync"] }

# Optional

h2 = { version = "0.3.9", optional = true }
http-body-util = { version = "=0.1.0-rc.3", optional = true }
h2 = { version = "0.4", optional = true }
http-body-util = { version = "0.1", optional = true }
httparse = { version = "1.8", optional = true }
httpdate = { version = "1.0", optional = true }
itoa = { version = "1", optional = true }
Expand All @@ -41,7 +41,7 @@ want = { version = "0.3", optional = true }

[dev-dependencies]
form_urlencoded = "1"
http-body-util = "=0.1.0-rc.3"
http-body-util = "0.1"
pretty_env_logger = "0.5"
spmc = "0.3"
serde = { version = "1.0", features = ["derive"] }
Expand Down
10 changes: 6 additions & 4 deletions src/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ use std::future::Future;
use std::io;
use std::marker::Unpin;
use std::pin::Pin;
use std::sync::{Arc, Mutex};
use std::task::{Context, Poll};

use crate::rt::{Read, ReadBufCursor, Write};
Expand All @@ -69,8 +70,9 @@ pub struct Upgraded {
/// A future for a possible HTTP upgrade.
///
/// If no upgrade was available, or it doesn't succeed, yields an `Error`.
#[derive(Clone)]
pub struct OnUpgrade {
rx: Option<oneshot::Receiver<crate::Result<Upgraded>>>,
rx: Option<Arc<Mutex<oneshot::Receiver<crate::Result<Upgraded>>>>>,
}

/// The deconstructed parts of an [`Upgraded`] type.
Expand Down Expand Up @@ -119,7 +121,7 @@ pub(super) struct Pending {
))]
pub(super) fn pending() -> (Pending, OnUpgrade) {
let (tx, rx) = oneshot::channel();
(Pending { tx }, OnUpgrade { rx: Some(rx) })
(Pending { tx }, OnUpgrade { rx: Some(Arc::new(Mutex::new(rx))) })
}

// ===== impl Upgraded =====
Expand Down Expand Up @@ -219,9 +221,9 @@ impl OnUpgrade {
impl Future for OnUpgrade {
type Output = Result<Upgraded, crate::Error>;

fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
match self.rx {
Some(ref mut rx) => Pin::new(rx).poll(cx).map(|res| match res {
Some(ref rx) => Pin::new(&mut *rx.lock().unwrap()).poll(cx).map(|res| match res {
Ok(Ok(upgraded)) => Ok(upgraded),
Ok(Err(err)) => Err(err),
Err(_oneshot_canceled) => Err(crate::Error::new_canceled().with(UpgradeExpected)),
Expand Down

0 comments on commit d98c9e5

Please sign in to comment.