Skip to content

Commit

Permalink
feat(lib): add raw_status feature in Cargo.toml
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
seanmonstar committed Jun 3, 2017
1 parent 76fc633 commit acd62cd
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ spmc = "0.2"
[features]
default = []
nightly = []
raw_status = []
39 changes: 36 additions & 3 deletions src/http/response.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fmt;

use header::{Header, Headers};
use http::{MessageHead, ResponseHead, Body, RawStatus};
use http::{MessageHead, ResponseHead, Body};
use status::StatusCode;
use version::HttpVersion;

Expand All @@ -10,7 +10,8 @@ pub struct Response<B = Body> {
version: HttpVersion,
headers: Headers,
status: StatusCode,
raw_status: RawStatus,
#[cfg(feature = "raw_status")]
raw_status: ::http::RawStatus,
body: Option<B>,
}

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

/// Set the `StatusCode` for this response.
#[inline]
Expand Down Expand Up @@ -101,6 +103,19 @@ impl Response<Body> {
}
}

#[cfg(not(feature = "raw_status"))]
impl<B> Default for Response<B> {
fn default() -> Response<B> {
Response::<B> {
version: Default::default(),
headers: Default::default(),
status: Default::default(),
body: None,
}
}
}

#[cfg(feature = "raw_status")]
impl<B> Default for Response<B> {
fn default() -> Response<B> {
Response::<B> {
Expand All @@ -125,6 +140,24 @@ impl fmt::Debug for Response {

/// Constructs a response using a received ResponseHead and optional body
#[inline]
#[cfg(not(feature = "raw_status"))]
pub fn from_wire<B>(incoming: ResponseHead, body: Option<B>) -> Response<B> {
let status = incoming.status();
trace!("Response::new");
debug!("version={:?}, status={:?}", incoming.version, status);
debug!("headers={:?}", incoming.headers);

Response::<B> {
status: status,
version: incoming.version,
headers: incoming.headers,
body: body,
}
}

/// Constructs a response using a received ResponseHead and optional body
#[inline]
#[cfg(feature = "raw_status")]
pub fn from_wire<B>(incoming: ResponseHead, body: Option<B>) -> Response<B> {
let status = incoming.status();
trace!("Response::new");
Expand Down

0 comments on commit acd62cd

Please sign in to comment.