Skip to content

Commit acd62cd

Browse files
committed
feat(lib): add raw_status feature in Cargo.toml
The `RawStatus` types on the `Response` are now gone by default. To make use of them, the `raw_status` feature must be enabled in `Cargo.toml`. BREAKING CHANGE: To use `RawStatus`, you must enable the `raw_status` crate feature.
1 parent 76fc633 commit acd62cd

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,4 @@ spmc = "0.2"
4343
[features]
4444
default = []
4545
nightly = []
46+
raw_status = []

src/http/response.rs

+36-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::fmt;
22

33
use header::{Header, Headers};
4-
use http::{MessageHead, ResponseHead, Body, RawStatus};
4+
use http::{MessageHead, ResponseHead, Body};
55
use status::StatusCode;
66
use version::HttpVersion;
77

@@ -10,7 +10,8 @@ pub struct Response<B = Body> {
1010
version: HttpVersion,
1111
headers: Headers,
1212
status: StatusCode,
13-
raw_status: RawStatus,
13+
#[cfg(feature = "raw_status")]
14+
raw_status: ::http::RawStatus,
1415
body: Option<B>,
1516
}
1617

@@ -42,7 +43,8 @@ impl<B> Response<B> {
4243
/// This method is only useful when inspecting the raw subject line from
4344
/// a received response.
4445
#[inline]
45-
pub fn status_raw(&self) -> &RawStatus { &self.raw_status }
46+
#[cfg(feature = "raw_status")]
47+
pub fn status_raw(&self) -> &::http::RawStatus { &self.raw_status }
4648

4749
/// Set the `StatusCode` for this response.
4850
#[inline]
@@ -101,6 +103,19 @@ impl Response<Body> {
101103
}
102104
}
103105

106+
#[cfg(not(feature = "raw_status"))]
107+
impl<B> Default for Response<B> {
108+
fn default() -> Response<B> {
109+
Response::<B> {
110+
version: Default::default(),
111+
headers: Default::default(),
112+
status: Default::default(),
113+
body: None,
114+
}
115+
}
116+
}
117+
118+
#[cfg(feature = "raw_status")]
104119
impl<B> Default for Response<B> {
105120
fn default() -> Response<B> {
106121
Response::<B> {
@@ -125,6 +140,24 @@ impl fmt::Debug for Response {
125140

126141
/// Constructs a response using a received ResponseHead and optional body
127142
#[inline]
143+
#[cfg(not(feature = "raw_status"))]
144+
pub fn from_wire<B>(incoming: ResponseHead, body: Option<B>) -> Response<B> {
145+
let status = incoming.status();
146+
trace!("Response::new");
147+
debug!("version={:?}, status={:?}", incoming.version, status);
148+
debug!("headers={:?}", incoming.headers);
149+
150+
Response::<B> {
151+
status: status,
152+
version: incoming.version,
153+
headers: incoming.headers,
154+
body: body,
155+
}
156+
}
157+
158+
/// Constructs a response using a received ResponseHead and optional body
159+
#[inline]
160+
#[cfg(feature = "raw_status")]
128161
pub fn from_wire<B>(incoming: ResponseHead, body: Option<B>) -> Response<B> {
129162
let status = incoming.status();
130163
trace!("Response::new");

0 commit comments

Comments
 (0)