Skip to content

Commit 933596a

Browse files
authored
Merge pull request #292 from pepoviola/stabilize-upgrade-response
stabilize upgrade in response
2 parents 68c4007 + 30613af commit 933596a

File tree

2 files changed

+1
-81
lines changed

2 files changed

+1
-81
lines changed

src/response.rs

Lines changed: 1 addition & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,9 @@ use crate::headers::{
1414
};
1515
use crate::mime::Mime;
1616
use crate::trailers::{self, Trailers};
17+
use crate::upgrade;
1718
use crate::{Body, Extensions, StatusCode, Version};
1819

19-
cfg_unstable! {
20-
use crate::upgrade;
21-
}
22-
23-
#[cfg(not(feature = "unstable"))]
2420
pin_project_lite::pin_project! {
2521
/// An HTTP response.
2622
///
@@ -44,38 +40,6 @@ pin_project_lite::pin_project! {
4440
has_trailers: bool,
4541
trailers_sender: Option<async_channel::Sender<Trailers>>,
4642
trailers_receiver: Option<async_channel::Receiver<Trailers>>,
47-
#[pin]
48-
body: Body,
49-
ext: Extensions,
50-
local_addr: Option<String>,
51-
peer_addr: Option<String>,
52-
}
53-
}
54-
55-
#[cfg(feature = "unstable")]
56-
pin_project_lite::pin_project! {
57-
/// An HTTP response.
58-
///
59-
/// # Examples
60-
///
61-
/// ```
62-
/// # fn main() -> Result<(), http_types::Error> {
63-
/// #
64-
/// use http_types::{Response, StatusCode};
65-
///
66-
/// let mut res = Response::new(StatusCode::Ok);
67-
/// res.set_body("Hello, Nori!");
68-
/// #
69-
/// # Ok(()) }
70-
/// ```
71-
#[derive(Debug)]
72-
pub struct Response {
73-
status: StatusCode,
74-
headers: Headers,
75-
version: Option<Version>,
76-
trailers_sender: Option<async_channel::Sender<Trailers>>,
77-
trailers_receiver: Option<async_channel::Receiver<Trailers>>,
78-
has_trailers: bool,
7943
upgrade_sender: Option<async_channel::Sender<upgrade::Connection>>,
8044
upgrade_receiver: Option<async_channel::Receiver<upgrade::Connection>>,
8145
has_upgrade: bool,
@@ -89,32 +53,6 @@ pin_project_lite::pin_project! {
8953

9054
impl Response {
9155
/// Create a new response.
92-
#[cfg(not(feature = "unstable"))]
93-
pub fn new<S>(status: S) -> Self
94-
where
95-
S: TryInto<StatusCode>,
96-
S::Error: Debug,
97-
{
98-
let status = status
99-
.try_into()
100-
.expect("Could not convert into a valid `StatusCode`");
101-
let (trailers_sender, trailers_receiver) = async_channel::bounded(1);
102-
Self {
103-
status,
104-
headers: Headers::new(),
105-
version: None,
106-
body: Body::empty(),
107-
trailers_sender: Some(trailers_sender),
108-
trailers_receiver: Some(trailers_receiver),
109-
has_trailers: false,
110-
ext: Extensions::new(),
111-
peer_addr: None,
112-
local_addr: None,
113-
}
114-
}
115-
116-
/// Create a new response.
117-
#[cfg(feature = "unstable")]
11856
pub fn new<S>(status: S) -> Self
11957
where
12058
S: TryInto<StatusCode>,
@@ -558,7 +496,6 @@ impl Response {
558496
}
559497

560498
/// Sends an upgrade connection to the a receiver.
561-
#[cfg(feature = "unstable")]
562499
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
563500
pub fn send_upgrade(&mut self) -> upgrade::Sender {
564501
self.has_upgrade = true;
@@ -570,7 +507,6 @@ impl Response {
570507
}
571508

572509
/// Receive an upgraded connection from a sender.
573-
#[cfg(feature = "unstable")]
574510
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
575511
pub async fn recv_upgrade(&mut self) -> upgrade::Receiver {
576512
self.has_upgrade = true;
@@ -582,7 +518,6 @@ impl Response {
582518
}
583519

584520
/// Returns `true` if a protocol upgrade is in progress.
585-
#[cfg(feature = "unstable")]
586521
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
587522
pub fn has_upgrade(&self) -> bool {
588523
self.has_upgrade
@@ -646,11 +581,8 @@ impl Clone for Response {
646581
trailers_sender: self.trailers_sender.clone(),
647582
trailers_receiver: self.trailers_receiver.clone(),
648583
has_trailers: false,
649-
#[cfg(feature = "unstable")]
650584
upgrade_sender: self.upgrade_sender.clone(),
651-
#[cfg(feature = "unstable")]
652585
upgrade_receiver: self.upgrade_receiver.clone(),
653-
#[cfg(feature = "unstable")]
654586
has_upgrade: false,
655587
body: Body::empty(),
656588
ext: Extensions::new(),

src/utils/mod.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,6 @@ use crate::{Error, Status, StatusCode};
99
use std::cmp::Ordering;
1010
use std::str::FromStr;
1111

12-
/// Declares unstable items.
13-
#[doc(hidden)]
14-
macro_rules! cfg_unstable {
15-
($($item:item)*) => {
16-
$(
17-
#[cfg(feature = "unstable")]
18-
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
19-
$item
20-
)*
21-
}
22-
}
23-
2412
/// Parse a weight of the form `q=0.123`.
2513
pub(crate) fn parse_weight(s: &str) -> crate::Result<f32> {
2614
let mut parts = s.split('=');

0 commit comments

Comments
 (0)