mirror of
https://github.com/actix/actix-web.git
synced 2024-11-23 01:51:11 +00:00
impl Default trait for HttpRequest
This commit is contained in:
parent
b62b303fdb
commit
45433f71e5
3 changed files with 13 additions and 10 deletions
|
@ -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)
|
* Transparent content compression/decompression (br, gzip, deflate)
|
||||||
* Configurable request routing
|
* Configurable request routing
|
||||||
* Multipart streams
|
* Multipart streams
|
||||||
* Middlewares
|
* Middlewares (Logger, Session included)
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
|
|
@ -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.
|
/// 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)
|
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> {
|
impl<S> Clone for HttpRequest<S> {
|
||||||
fn clone(&self) -> HttpRequest<S> {
|
fn clone(&self) -> HttpRequest<S> {
|
||||||
HttpRequest(Rc::clone(&self.0), Rc::clone(&self.1))
|
HttpRequest(Rc::clone(&self.0), Rc::clone(&self.1))
|
||||||
|
|
|
@ -39,13 +39,13 @@ impl Pipeline {
|
||||||
Pipeline(PipelineState::Starting(res)),
|
Pipeline(PipelineState::Starting(res)),
|
||||||
Err(err) =>
|
Err(err) =>
|
||||||
Pipeline(PipelineState::Error(
|
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 {
|
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) {
|
pub(crate) fn disconnected(&mut self) {
|
||||||
|
@ -79,7 +79,7 @@ impl Pipeline {
|
||||||
self.0 = PipelineState::Handle(h),
|
self.0 = PipelineState::Handle(h),
|
||||||
Err(err) =>
|
Err(err) =>
|
||||||
self.0 = PipelineState::Error(
|
self.0 = PipelineState::Error(
|
||||||
Box::new((Task::reply(err), HttpRequest::for_error())))
|
Box::new((Task::reply(err), HttpRequest::default())))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PipelineState::Handle(mut st) => {
|
PipelineState::Handle(mut st) => {
|
||||||
|
|
Loading…
Reference in a new issue