From a255a6fb6967e77fa821633b06a0662a40755502 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Tue, 3 Apr 2018 17:37:17 -0700 Subject: [PATCH] use build_response method --- src/httpresponse.rs | 24 ++++++++++++------------ src/json.rs | 5 +++-- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/httpresponse.rs b/src/httpresponse.rs index 1f763159..5edb6de5 100644 --- a/src/httpresponse.rs +++ b/src/httpresponse.rs @@ -626,8 +626,8 @@ impl Responder for &'static str { type Item = HttpResponse; type Error = Error; - fn respond_to(self, _: HttpRequest) -> Result { - Ok(HttpResponse::Ok() + fn respond_to(self, req: HttpRequest) -> Result { + Ok(req.build_response(StatusCode::OK) .content_type("text/plain; charset=utf-8") .body(self)) } @@ -645,8 +645,8 @@ impl Responder for &'static [u8] { type Item = HttpResponse; type Error = Error; - fn respond_to(self, _: HttpRequest) -> Result { - Ok(HttpResponse::Ok() + fn respond_to(self, req: HttpRequest) -> Result { + Ok(req.build_response(StatusCode::OK) .content_type("application/octet-stream") .body(self)) } @@ -664,8 +664,8 @@ impl Responder for String { type Item = HttpResponse; type Error = Error; - fn respond_to(self, _: HttpRequest) -> Result { - Ok(HttpResponse::Ok() + fn respond_to(self, req: HttpRequest) -> Result { + Ok(req.build_response(StatusCode::OK) .content_type("text/plain; charset=utf-8") .body(self)) } @@ -683,8 +683,8 @@ impl<'a> Responder for &'a String { type Item = HttpResponse; type Error = Error; - fn respond_to(self, _: HttpRequest) -> Result { - Ok(HttpResponse::Ok() + fn respond_to(self, req: HttpRequest) -> Result { + Ok(req.build_response(StatusCode::OK) .content_type("text/plain; charset=utf-8") .body(self)) } @@ -702,8 +702,8 @@ impl Responder for Bytes { type Item = HttpResponse; type Error = Error; - fn respond_to(self, _: HttpRequest) -> Result { - Ok(HttpResponse::Ok() + fn respond_to(self, req: HttpRequest) -> Result { + Ok(req.build_response(StatusCode::OK) .content_type("application/octet-stream") .body(self)) } @@ -721,8 +721,8 @@ impl Responder for BytesMut { type Item = HttpResponse; type Error = Error; - fn respond_to(self, _: HttpRequest) -> Result { - Ok(HttpResponse::Ok() + fn respond_to(self, req: HttpRequest) -> Result { + Ok(req.build_response(StatusCode::OK) .content_type("application/octet-stream") .body(self)) } diff --git a/src/json.rs b/src/json.rs index 3c8f81e8..bef34960 100644 --- a/src/json.rs +++ b/src/json.rs @@ -11,6 +11,7 @@ use serde::de::DeserializeOwned; use error::{Error, JsonPayloadError, PayloadError}; use handler::{Responder, FromRequest}; +use http::StatusCode; use httpmessage::HttpMessage; use httprequest::HttpRequest; use httpresponse::HttpResponse; @@ -71,10 +72,10 @@ impl Responder for Json { type Item = HttpResponse; type Error = Error; - fn respond_to(self, _: HttpRequest) -> Result { + fn respond_to(self, req: HttpRequest) -> Result { let body = serde_json::to_string(&self.0)?; - Ok(HttpResponse::Ok() + Ok(req.build_response(StatusCode::OK) .content_type("application/json") .body(body)) }