From 45433f71e5e7ea0963a0074bb83e077e86f2e351 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Sun, 26 Nov 2017 22:20:28 -0800 Subject: [PATCH] impl Default trait for HttpRequest --- README.md | 2 +- src/httprequest.rs | 15 +++++++++------ src/pipeline.rs | 6 +++--- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index b4c3773f3..d6cfb95a3 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ Actix web is licensed under the [Apache-2.0 license](http://opensource.org/licen * Transparent content compression/decompression (br, gzip, deflate) * Configurable request routing * Multipart streams - * Middlewares + * Middlewares (Logger, Session included) ## Usage diff --git a/src/httprequest.rs b/src/httprequest.rs index f2c1d6012..3c0f6edcb 100644 --- a/src/httprequest.rs +++ b/src/httprequest.rs @@ -75,13 +75,8 @@ impl HttpRequest<()> { ) } - /// Construct request for error response. - pub(crate) fn for_error() -> HttpRequest { - HttpRequest(Rc::new(HttpMessage::default()), Rc::new(())) - } - /// Construct new http request with state. - pub(crate) fn with_state(self, state: Rc) -> HttpRequest { + pub fn with_state(self, state: Rc) -> HttpRequest { HttpRequest(self.0, state) } } @@ -345,6 +340,14 @@ impl HttpRequest { } } +impl Default for HttpRequest<()> { + + /// Construct default request + fn default() -> HttpRequest { + HttpRequest(Rc::new(HttpMessage::default()), Rc::new(())) + } +} + impl Clone for HttpRequest { fn clone(&self) -> HttpRequest { HttpRequest(Rc::clone(&self.0), Rc::clone(&self.1)) diff --git a/src/pipeline.rs b/src/pipeline.rs index 218755ba2..7723cefa8 100644 --- a/src/pipeline.rs +++ b/src/pipeline.rs @@ -39,13 +39,13 @@ impl Pipeline { Pipeline(PipelineState::Starting(res)), Err(err) => Pipeline(PipelineState::Error( - Box::new((Task::reply(err), HttpRequest::for_error())))) + Box::new((Task::reply(err), HttpRequest::default())))) } } } pub fn error>(resp: R) -> Self { - Pipeline(PipelineState::Error(Box::new((Task::reply(resp), HttpRequest::for_error())))) + Pipeline(PipelineState::Error(Box::new((Task::reply(resp), HttpRequest::default())))) } pub(crate) fn disconnected(&mut self) { @@ -79,7 +79,7 @@ impl Pipeline { self.0 = PipelineState::Handle(h), Err(err) => self.0 = PipelineState::Error( - Box::new((Task::reply(err), HttpRequest::for_error()))) + Box::new((Task::reply(err), HttpRequest::default()))) } } PipelineState::Handle(mut st) => {