1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-08-31 17:07:01 +02:00

introduce custom FromRequest traint for conversion into Reply

This commit is contained in:
Nikolay Kim
2017-12-02 16:37:21 -08:00
parent 187948ddd1
commit 61744b68a1
6 changed files with 82 additions and 39 deletions

View File

@@ -3,8 +3,7 @@
use http::StatusCode;
use body::Body;
use route::Reply;
use route::RouteHandler;
use route::{Reply, RouteHandler, FromRequest};
use httprequest::HttpRequest;
use httpresponse::{HttpResponse, HttpResponseBuilder};
@@ -74,6 +73,12 @@ impl<S> RouteHandler<S> for StaticResponse {
}
}
impl FromRequest for StaticResponse {
fn from_request(self, _: HttpRequest) -> Reply {
Reply::response(HttpResponse::new(self.0, Body::Empty))
}
}
impl From<StaticResponse> for HttpResponse {
fn from(st: StaticResponse) -> Self {
st.response()