mirror of
https://github.com/actix/actix-web.git
synced 2024-11-26 11:31:09 +00:00
Use more ergonomic actix_web::Error instead of http::Error for HttpResponseBuilder::body()
This commit is contained in:
parent
e8a1850c79
commit
e49910cdab
4 changed files with 26 additions and 23 deletions
|
@ -4,6 +4,8 @@
|
||||||
|
|
||||||
* Fix client connection pooling
|
* Fix client connection pooling
|
||||||
|
|
||||||
|
* Use more ergonomic `actix_web::Error` instead of `http::Error` for `HttpResponseBuilder::body()`
|
||||||
|
|
||||||
|
|
||||||
## 0.4.10 (2018-03-20)
|
## 0.4.10 (2018-03-20)
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ use std::marker::PhantomData;
|
||||||
|
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use futures::future::{Future, ok, err};
|
use futures::future::{Future, ok, err};
|
||||||
use http::{header, StatusCode, Error as HttpError};
|
use http::{header, StatusCode};
|
||||||
|
|
||||||
use body::Body;
|
use body::Body;
|
||||||
use error::Error;
|
use error::Error;
|
||||||
|
@ -412,7 +412,7 @@ impl NormalizePath {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S> Handler<S> for NormalizePath {
|
impl<S> Handler<S> for NormalizePath {
|
||||||
type Result = Result<HttpResponse, HttpError>;
|
type Result = Result<HttpResponse, Error>;
|
||||||
|
|
||||||
fn handle(&mut self, req: HttpRequest<S>) -> Self::Result {
|
fn handle(&mut self, req: HttpRequest<S>) -> Self::Result {
|
||||||
if let Some(router) = req.router() {
|
if let Some(router) = req.router() {
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
//! Basic http responses
|
//! Basic http responses
|
||||||
#![allow(non_upper_case_globals)]
|
#![allow(non_upper_case_globals)]
|
||||||
use http::{StatusCode, Error as HttpError};
|
use http::StatusCode;
|
||||||
|
|
||||||
use body::Body;
|
use body::Body;
|
||||||
|
use error::Error;
|
||||||
use handler::{Reply, Handler, RouteHandler, Responder};
|
use handler::{Reply, Handler, RouteHandler, Responder};
|
||||||
use httprequest::HttpRequest;
|
use httprequest::HttpRequest;
|
||||||
use httpresponse::{HttpResponse, HttpResponseBuilder};
|
use httpresponse::{HttpResponse, HttpResponseBuilder};
|
||||||
|
@ -211,9 +212,9 @@ impl<S> RouteHandler<S> for StaticResponse {
|
||||||
|
|
||||||
impl Responder for StaticResponse {
|
impl Responder for StaticResponse {
|
||||||
type Item = HttpResponse;
|
type Item = HttpResponse;
|
||||||
type Error = HttpError;
|
type Error = Error;
|
||||||
|
|
||||||
fn respond_to(self, _: HttpRequest) -> Result<HttpResponse, HttpError> {
|
fn respond_to(self, _: HttpRequest) -> Result<HttpResponse, Error> {
|
||||||
self.build().body(Body::Empty)
|
self.build().body(Body::Empty)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -505,9 +505,9 @@ impl HttpResponseBuilder {
|
||||||
/// Set a body and generate `HttpResponse`.
|
/// Set a body and generate `HttpResponse`.
|
||||||
///
|
///
|
||||||
/// `HttpResponseBuilder` can not be used after this call.
|
/// `HttpResponseBuilder` can not be used after this call.
|
||||||
pub fn body<B: Into<Body>>(&mut self, body: B) -> Result<HttpResponse, HttpError> {
|
pub fn body<B: Into<Body>>(&mut self, body: B) -> Result<HttpResponse, Error> {
|
||||||
if let Some(e) = self.err.take() {
|
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");
|
let mut response = self.response.take().expect("cannot reuse response builder");
|
||||||
if let Some(ref jar) = self.cookies {
|
if let Some(ref jar) = self.cookies {
|
||||||
|
@ -524,7 +524,7 @@ impl HttpResponseBuilder {
|
||||||
/// Set a streaming body and generate `HttpResponse`.
|
/// Set a streaming body and generate `HttpResponse`.
|
||||||
///
|
///
|
||||||
/// `HttpResponseBuilder` can not be used after this call.
|
/// `HttpResponseBuilder` can not be used after this call.
|
||||||
pub fn streaming<S, E>(&mut self, stream: S) -> Result<HttpResponse, HttpError>
|
pub fn streaming<S, E>(&mut self, stream: S) -> Result<HttpResponse, Error>
|
||||||
where S: Stream<Item=Bytes, Error=E> + 'static,
|
where S: Stream<Item=Bytes, Error=E> + 'static,
|
||||||
E: Into<Error>,
|
E: Into<Error>,
|
||||||
{
|
{
|
||||||
|
@ -552,7 +552,7 @@ impl HttpResponseBuilder {
|
||||||
/// Set an empty body and generate `HttpResponse`
|
/// Set an empty body and generate `HttpResponse`
|
||||||
///
|
///
|
||||||
/// `HttpResponseBuilder` can not be used after this call.
|
/// `HttpResponseBuilder` can not be used after this call.
|
||||||
pub fn finish(&mut self) -> Result<HttpResponse, HttpError> {
|
pub fn finish(&mut self) -> Result<HttpResponse, Error> {
|
||||||
self.body(Body::Empty)
|
self.body(Body::Empty)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -596,10 +596,10 @@ impl From<HttpResponseBuilder> for HttpResponse {
|
||||||
|
|
||||||
impl Responder for HttpResponseBuilder {
|
impl Responder for HttpResponseBuilder {
|
||||||
type Item = HttpResponse;
|
type Item = HttpResponse;
|
||||||
type Error = HttpError;
|
type Error = Error;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn respond_to(mut self, _: HttpRequest) -> Result<HttpResponse, HttpError> {
|
fn respond_to(mut self, _: HttpRequest) -> Result<HttpResponse, Error> {
|
||||||
self.finish()
|
self.finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -615,9 +615,9 @@ impl From<&'static str> for HttpResponse {
|
||||||
|
|
||||||
impl Responder for &'static str {
|
impl Responder for &'static str {
|
||||||
type Item = HttpResponse;
|
type Item = HttpResponse;
|
||||||
type Error = HttpError;
|
type Error = Error;
|
||||||
|
|
||||||
fn respond_to(self, _: HttpRequest) -> Result<HttpResponse, HttpError> {
|
fn respond_to(self, _: HttpRequest) -> Result<HttpResponse, Error> {
|
||||||
HttpResponse::build(StatusCode::OK)
|
HttpResponse::build(StatusCode::OK)
|
||||||
.content_type("text/plain; charset=utf-8")
|
.content_type("text/plain; charset=utf-8")
|
||||||
.body(self)
|
.body(self)
|
||||||
|
@ -635,9 +635,9 @@ impl From<&'static [u8]> for HttpResponse {
|
||||||
|
|
||||||
impl Responder for &'static [u8] {
|
impl Responder for &'static [u8] {
|
||||||
type Item = HttpResponse;
|
type Item = HttpResponse;
|
||||||
type Error = HttpError;
|
type Error = Error;
|
||||||
|
|
||||||
fn respond_to(self, _: HttpRequest) -> Result<HttpResponse, HttpError> {
|
fn respond_to(self, _: HttpRequest) -> Result<HttpResponse, Error> {
|
||||||
HttpResponse::build(StatusCode::OK)
|
HttpResponse::build(StatusCode::OK)
|
||||||
.content_type("application/octet-stream")
|
.content_type("application/octet-stream")
|
||||||
.body(self)
|
.body(self)
|
||||||
|
@ -655,9 +655,9 @@ impl From<String> for HttpResponse {
|
||||||
|
|
||||||
impl Responder for String {
|
impl Responder for String {
|
||||||
type Item = HttpResponse;
|
type Item = HttpResponse;
|
||||||
type Error = HttpError;
|
type Error = Error;
|
||||||
|
|
||||||
fn respond_to(self, _: HttpRequest) -> Result<HttpResponse, HttpError> {
|
fn respond_to(self, _: HttpRequest) -> Result<HttpResponse, Error> {
|
||||||
HttpResponse::build(StatusCode::OK)
|
HttpResponse::build(StatusCode::OK)
|
||||||
.content_type("text/plain; charset=utf-8")
|
.content_type("text/plain; charset=utf-8")
|
||||||
.body(self)
|
.body(self)
|
||||||
|
@ -675,9 +675,9 @@ impl<'a> From<&'a String> for HttpResponse {
|
||||||
|
|
||||||
impl<'a> Responder for &'a String {
|
impl<'a> Responder for &'a String {
|
||||||
type Item = HttpResponse;
|
type Item = HttpResponse;
|
||||||
type Error = HttpError;
|
type Error = Error;
|
||||||
|
|
||||||
fn respond_to(self, _: HttpRequest) -> Result<HttpResponse, HttpError> {
|
fn respond_to(self, _: HttpRequest) -> Result<HttpResponse, Error> {
|
||||||
HttpResponse::build(StatusCode::OK)
|
HttpResponse::build(StatusCode::OK)
|
||||||
.content_type("text/plain; charset=utf-8")
|
.content_type("text/plain; charset=utf-8")
|
||||||
.body(self)
|
.body(self)
|
||||||
|
@ -695,9 +695,9 @@ impl From<Bytes> for HttpResponse {
|
||||||
|
|
||||||
impl Responder for Bytes {
|
impl Responder for Bytes {
|
||||||
type Item = HttpResponse;
|
type Item = HttpResponse;
|
||||||
type Error = HttpError;
|
type Error = Error;
|
||||||
|
|
||||||
fn respond_to(self, _: HttpRequest) -> Result<HttpResponse, HttpError> {
|
fn respond_to(self, _: HttpRequest) -> Result<HttpResponse, Error> {
|
||||||
HttpResponse::build(StatusCode::OK)
|
HttpResponse::build(StatusCode::OK)
|
||||||
.content_type("application/octet-stream")
|
.content_type("application/octet-stream")
|
||||||
.body(self)
|
.body(self)
|
||||||
|
@ -715,9 +715,9 @@ impl From<BytesMut> for HttpResponse {
|
||||||
|
|
||||||
impl Responder for BytesMut {
|
impl Responder for BytesMut {
|
||||||
type Item = HttpResponse;
|
type Item = HttpResponse;
|
||||||
type Error = HttpError;
|
type Error = Error;
|
||||||
|
|
||||||
fn respond_to(self, _: HttpRequest) -> Result<HttpResponse, HttpError> {
|
fn respond_to(self, _: HttpRequest) -> Result<HttpResponse, Error> {
|
||||||
HttpResponse::build(StatusCode::OK)
|
HttpResponse::build(StatusCode::OK)
|
||||||
.content_type("application/octet-stream")
|
.content_type("application/octet-stream")
|
||||||
.body(self)
|
.body(self)
|
||||||
|
|
Loading…
Reference in a new issue