From 573abec5307b990fe40bd5c0f95e9edd005e2857 Mon Sep 17 00:00:00 2001 From: Pepo Viola Date: Mon, 30 Nov 2020 09:49:08 -0300 Subject: [PATCH 1/3] stabilize upgrade in response --- src/response.rs | 68 +------------------------------------------------ 1 file changed, 1 insertion(+), 67 deletions(-) diff --git a/src/response.rs b/src/response.rs index c9e13306..10cbd3b5 100644 --- a/src/response.rs +++ b/src/response.rs @@ -15,10 +15,7 @@ use crate::headers::{ use crate::mime::Mime; use crate::trailers::{self, Trailers}; use crate::{Body, Extensions, StatusCode, Version}; - -cfg_unstable! { - use crate::upgrade; -} +use crate::upgrade; #[cfg(not(feature = "unstable"))] pin_project_lite::pin_project! { @@ -44,38 +41,6 @@ pin_project_lite::pin_project! { has_trailers: bool, trailers_sender: Option>, trailers_receiver: Option>, - #[pin] - body: Body, - ext: Extensions, - local_addr: Option, - peer_addr: Option, - } -} - -#[cfg(feature = "unstable")] -pin_project_lite::pin_project! { - /// An HTTP response. - /// - /// # Examples - /// - /// ``` - /// # fn main() -> Result<(), http_types::Error> { - /// # - /// use http_types::{Response, StatusCode}; - /// - /// let mut res = Response::new(StatusCode::Ok); - /// res.set_body("Hello, Nori!"); - /// # - /// # Ok(()) } - /// ``` - #[derive(Debug)] - pub struct Response { - status: StatusCode, - headers: Headers, - version: Option, - trailers_sender: Option>, - trailers_receiver: Option>, - has_trailers: bool, upgrade_sender: Option>, upgrade_receiver: Option>, has_upgrade: bool, @@ -91,31 +56,6 @@ impl Response { /// Create a new response. #[cfg(not(feature = "unstable"))] pub fn new(status: S) -> Self - where - S: TryInto, - S::Error: Debug, - { - let status = status - .try_into() - .expect("Could not convert into a valid `StatusCode`"); - let (trailers_sender, trailers_receiver) = async_channel::bounded(1); - Self { - status, - headers: Headers::new(), - version: None, - body: Body::empty(), - trailers_sender: Some(trailers_sender), - trailers_receiver: Some(trailers_receiver), - has_trailers: false, - ext: Extensions::new(), - peer_addr: None, - local_addr: None, - } - } - - /// Create a new response. - #[cfg(feature = "unstable")] - pub fn new(status: S) -> Self where S: TryInto, S::Error: Debug, @@ -558,7 +498,6 @@ impl Response { } /// Sends an upgrade connection to the a receiver. - #[cfg(feature = "unstable")] #[cfg_attr(feature = "docs", doc(cfg(unstable)))] pub fn send_upgrade(&mut self) -> upgrade::Sender { self.has_upgrade = true; @@ -570,7 +509,6 @@ impl Response { } /// Receive an upgraded connection from a sender. - #[cfg(feature = "unstable")] #[cfg_attr(feature = "docs", doc(cfg(unstable)))] pub async fn recv_upgrade(&mut self) -> upgrade::Receiver { self.has_upgrade = true; @@ -582,7 +520,6 @@ impl Response { } /// Returns `true` if a protocol upgrade is in progress. - #[cfg(feature = "unstable")] #[cfg_attr(feature = "docs", doc(cfg(unstable)))] pub fn has_upgrade(&self) -> bool { self.has_upgrade @@ -646,11 +583,8 @@ impl Clone for Response { trailers_sender: self.trailers_sender.clone(), trailers_receiver: self.trailers_receiver.clone(), has_trailers: false, - #[cfg(feature = "unstable")] upgrade_sender: self.upgrade_sender.clone(), - #[cfg(feature = "unstable")] upgrade_receiver: self.upgrade_receiver.clone(), - #[cfg(feature = "unstable")] has_upgrade: false, body: Body::empty(), ext: Extensions::new(), From a1481568d3e4dd5cb9796c3f88a820324d8a1ae5 Mon Sep 17 00:00:00 2001 From: Pepo Viola Date: Mon, 30 Nov 2020 18:01:25 -0300 Subject: [PATCH 2/3] needed changes for ci and clean --- src/response.rs | 2 -- src/utils/mod.rs | 12 ------------ 2 files changed, 14 deletions(-) diff --git a/src/response.rs b/src/response.rs index 10cbd3b5..ef3397ac 100644 --- a/src/response.rs +++ b/src/response.rs @@ -17,7 +17,6 @@ use crate::trailers::{self, Trailers}; use crate::{Body, Extensions, StatusCode, Version}; use crate::upgrade; -#[cfg(not(feature = "unstable"))] pin_project_lite::pin_project! { /// An HTTP response. /// @@ -54,7 +53,6 @@ pin_project_lite::pin_project! { impl Response { /// Create a new response. - #[cfg(not(feature = "unstable"))] pub fn new(status: S) -> Self where S: TryInto, diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 394f689b..d2b01a71 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -9,18 +9,6 @@ use crate::{Error, Status, StatusCode}; use std::cmp::Ordering; use std::str::FromStr; -/// Declares unstable items. -#[doc(hidden)] -macro_rules! cfg_unstable { - ($($item:item)*) => { - $( - #[cfg(feature = "unstable")] - #[cfg_attr(feature = "docs", doc(cfg(unstable)))] - $item - )* - } -} - /// Parse a weight of the form `q=0.123`. pub(crate) fn parse_weight(s: &str) -> crate::Result { let mut parts = s.split('='); From 30613afb29b5c3062bdb451c68b471f4ab476737 Mon Sep 17 00:00:00 2001 From: Pepo Viola Date: Mon, 30 Nov 2020 18:08:45 -0300 Subject: [PATCH 3/3] fmt --- src/response.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/response.rs b/src/response.rs index ef3397ac..766dacba 100644 --- a/src/response.rs +++ b/src/response.rs @@ -14,8 +14,8 @@ use crate::headers::{ }; use crate::mime::Mime; use crate::trailers::{self, Trailers}; -use crate::{Body, Extensions, StatusCode, Version}; use crate::upgrade; +use crate::{Body, Extensions, StatusCode, Version}; pin_project_lite::pin_project! { /// An HTTP response.