diff --git a/CHANGES.md b/CHANGES.md index 3049061cc..03ae7a25d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,8 @@ * Fix client connection pooling +* Use more ergonomic `actix_web::Error` instead of `http::Error` for `HttpResponseBuilder::body()` + ## 0.4.10 (2018-03-20) diff --git a/src/handler.rs b/src/handler.rs index fd689699e..69839073a 100644 --- a/src/handler.rs +++ b/src/handler.rs @@ -2,7 +2,7 @@ use std::marker::PhantomData; use regex::Regex; use futures::future::{Future, ok, err}; -use http::{header, StatusCode, Error as HttpError}; +use http::{header, StatusCode}; use body::Body; use error::Error; @@ -412,7 +412,7 @@ impl NormalizePath { } impl Handler for NormalizePath { - type Result = Result; + type Result = Result; fn handle(&mut self, req: HttpRequest) -> Self::Result { if let Some(router) = req.router() { diff --git a/src/httpcodes.rs b/src/httpcodes.rs index 2a1165a0e..d3b803dcc 100644 --- a/src/httpcodes.rs +++ b/src/httpcodes.rs @@ -1,8 +1,9 @@ //! Basic http responses #![allow(non_upper_case_globals)] -use http::{StatusCode, Error as HttpError}; +use http::StatusCode; use body::Body; +use error::Error; use handler::{Reply, Handler, RouteHandler, Responder}; use httprequest::HttpRequest; use httpresponse::{HttpResponse, HttpResponseBuilder}; @@ -211,9 +212,9 @@ impl RouteHandler for StaticResponse { impl Responder for StaticResponse { type Item = HttpResponse; - type Error = HttpError; + type Error = Error; - fn respond_to(self, _: HttpRequest) -> Result { + fn respond_to(self, _: HttpRequest) -> Result { self.build().body(Body::Empty) } } diff --git a/src/httpresponse.rs b/src/httpresponse.rs index 326281f78..eafe4207b 100644 --- a/src/httpresponse.rs +++ b/src/httpresponse.rs @@ -505,9 +505,9 @@ impl HttpResponseBuilder { /// Set a body and generate `HttpResponse`. /// /// `HttpResponseBuilder` can not be used after this call. - pub fn body>(&mut self, body: B) -> Result { + pub fn body>(&mut self, body: B) -> Result { if let Some(e) = self.err.take() { - return Err(e) + return Err(e.into()) } let mut response = self.response.take().expect("cannot reuse response builder"); if let Some(ref jar) = self.cookies { @@ -524,7 +524,7 @@ impl HttpResponseBuilder { /// Set a streaming body and generate `HttpResponse`. /// /// `HttpResponseBuilder` can not be used after this call. - pub fn streaming(&mut self, stream: S) -> Result + pub fn streaming(&mut self, stream: S) -> Result where S: Stream + 'static, E: Into, { @@ -552,7 +552,7 @@ impl HttpResponseBuilder { /// Set an empty body and generate `HttpResponse` /// /// `HttpResponseBuilder` can not be used after this call. - pub fn finish(&mut self) -> Result { + pub fn finish(&mut self) -> Result { self.body(Body::Empty) } @@ -596,10 +596,10 @@ impl From for HttpResponse { impl Responder for HttpResponseBuilder { type Item = HttpResponse; - type Error = HttpError; + type Error = Error; #[inline] - fn respond_to(mut self, _: HttpRequest) -> Result { + fn respond_to(mut self, _: HttpRequest) -> Result { self.finish() } } @@ -615,9 +615,9 @@ impl From<&'static str> for HttpResponse { impl Responder for &'static str { type Item = HttpResponse; - type Error = HttpError; + type Error = Error; - fn respond_to(self, _: HttpRequest) -> Result { + fn respond_to(self, _: HttpRequest) -> Result { HttpResponse::build(StatusCode::OK) .content_type("text/plain; charset=utf-8") .body(self) @@ -635,9 +635,9 @@ impl From<&'static [u8]> for HttpResponse { impl Responder for &'static [u8] { type Item = HttpResponse; - type Error = HttpError; + type Error = Error; - fn respond_to(self, _: HttpRequest) -> Result { + fn respond_to(self, _: HttpRequest) -> Result { HttpResponse::build(StatusCode::OK) .content_type("application/octet-stream") .body(self) @@ -655,9 +655,9 @@ impl From for HttpResponse { impl Responder for String { type Item = HttpResponse; - type Error = HttpError; + type Error = Error; - fn respond_to(self, _: HttpRequest) -> Result { + fn respond_to(self, _: HttpRequest) -> Result { HttpResponse::build(StatusCode::OK) .content_type("text/plain; charset=utf-8") .body(self) @@ -675,9 +675,9 @@ impl<'a> From<&'a String> for HttpResponse { impl<'a> Responder for &'a String { type Item = HttpResponse; - type Error = HttpError; + type Error = Error; - fn respond_to(self, _: HttpRequest) -> Result { + fn respond_to(self, _: HttpRequest) -> Result { HttpResponse::build(StatusCode::OK) .content_type("text/plain; charset=utf-8") .body(self) @@ -695,9 +695,9 @@ impl From for HttpResponse { impl Responder for Bytes { type Item = HttpResponse; - type Error = HttpError; + type Error = Error; - fn respond_to(self, _: HttpRequest) -> Result { + fn respond_to(self, _: HttpRequest) -> Result { HttpResponse::build(StatusCode::OK) .content_type("application/octet-stream") .body(self) @@ -715,9 +715,9 @@ impl From for HttpResponse { impl Responder for BytesMut { type Item = HttpResponse; - type Error = HttpError; + type Error = Error; - fn respond_to(self, _: HttpRequest) -> Result { + fn respond_to(self, _: HttpRequest) -> Result { HttpResponse::build(StatusCode::OK) .content_type("application/octet-stream") .body(self)