From acd62cda446e4c647716a2d595342360dc24a080 Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Sat, 3 Jun 2017 16:20:22 -0700 Subject: [PATCH] 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. --- Cargo.toml | 1 + src/http/response.rs | 39 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 80cd4bed56..74f206c2ea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,3 +43,4 @@ spmc = "0.2" [features] default = [] nightly = [] +raw_status = [] diff --git a/src/http/response.rs b/src/http/response.rs index 4f1dd7fd22..53fa104e9b 100644 --- a/src/http/response.rs +++ b/src/http/response.rs @@ -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; @@ -10,7 +10,8 @@ pub struct Response { version: HttpVersion, headers: Headers, status: StatusCode, - raw_status: RawStatus, + #[cfg(feature = "raw_status")] + raw_status: ::http::RawStatus, body: Option, } @@ -42,7 +43,8 @@ impl Response { /// 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] @@ -101,6 +103,19 @@ impl Response { } } +#[cfg(not(feature = "raw_status"))] +impl Default for Response { + fn default() -> Response { + Response:: { + version: Default::default(), + headers: Default::default(), + status: Default::default(), + body: None, + } + } +} + +#[cfg(feature = "raw_status")] impl Default for Response { fn default() -> Response { Response:: { @@ -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(incoming: ResponseHead, body: Option) -> Response { + let status = incoming.status(); + trace!("Response::new"); + debug!("version={:?}, status={:?}", incoming.version, status); + debug!("headers={:?}", incoming.headers); + + Response:: { + 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(incoming: ResponseHead, body: Option) -> Response { let status = incoming.status(); trace!("Response::new");