1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-11-26 03:21:08 +00:00

impl Default trait for HttpRequest

This commit is contained in:
Nikolay Kim 2017-11-26 22:20:28 -08:00
parent b62b303fdb
commit 45433f71e5
3 changed files with 13 additions and 10 deletions

View file

@ -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

View file

@ -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<S>(self, state: Rc<S>) -> HttpRequest<S> {
pub fn with_state<S>(self, state: Rc<S>) -> HttpRequest<S> {
HttpRequest(self.0, state)
}
}
@ -345,6 +340,14 @@ impl<S> HttpRequest<S> {
}
}
impl Default for HttpRequest<()> {
/// Construct default request
fn default() -> HttpRequest {
HttpRequest(Rc::new(HttpMessage::default()), Rc::new(()))
}
}
impl<S> Clone for HttpRequest<S> {
fn clone(&self) -> HttpRequest<S> {
HttpRequest(Rc::clone(&self.0), Rc::clone(&self.1))

View file

@ -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<R: Into<HttpResponse>>(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) => {