1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-28 09:42:40 +01:00

use build_response method

This commit is contained in:
Nikolay Kim 2018-04-03 17:37:17 -07:00
parent b693d5491b
commit a255a6fb69
2 changed files with 15 additions and 14 deletions

View File

@ -626,8 +626,8 @@ impl Responder for &'static str {
type Item = HttpResponse;
type Error = Error;
fn respond_to(self, _: HttpRequest) -> Result<HttpResponse, Error> {
Ok(HttpResponse::Ok()
fn respond_to(self, req: HttpRequest) -> Result<HttpResponse, Error> {
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<HttpResponse, Error> {
Ok(HttpResponse::Ok()
fn respond_to(self, req: HttpRequest) -> Result<HttpResponse, Error> {
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<HttpResponse, Error> {
Ok(HttpResponse::Ok()
fn respond_to(self, req: HttpRequest) -> Result<HttpResponse, Error> {
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<HttpResponse, Error> {
Ok(HttpResponse::Ok()
fn respond_to(self, req: HttpRequest) -> Result<HttpResponse, Error> {
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<HttpResponse, Error> {
Ok(HttpResponse::Ok()
fn respond_to(self, req: HttpRequest) -> Result<HttpResponse, Error> {
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<HttpResponse, Error> {
Ok(HttpResponse::Ok()
fn respond_to(self, req: HttpRequest) -> Result<HttpResponse, Error> {
Ok(req.build_response(StatusCode::OK)
.content_type("application/octet-stream")
.body(self))
}

View File

@ -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<T: Serialize> Responder for Json<T> {
type Item = HttpResponse;
type Error = Error;
fn respond_to(self, _: HttpRequest) -> Result<HttpResponse, Error> {
fn respond_to(self, req: HttpRequest) -> Result<HttpResponse, Error> {
let body = serde_json::to_string(&self.0)?;
Ok(HttpResponse::Ok()
Ok(req.build_response(StatusCode::OK)
.content_type("application/json")
.body(body))
}