From b535adf637ea85176bfaabc78e7f6eed7358ef41 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Sat, 2 Mar 2019 21:22:01 -0800 Subject: [PATCH] add IntoFuture impl for Response and ResponseBuilder --- src/header/common/mod.rs | 6 +++--- src/response.rs | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/header/common/mod.rs b/src/header/common/mod.rs index adc7484a9..30dfcaa6d 100644 --- a/src/header/common/mod.rs +++ b/src/header/common/mod.rs @@ -81,7 +81,7 @@ macro_rules! test_header { let a: Vec> = raw.iter().map(|x| x.to_vec()).collect(); let mut req = test::TestRequest::default(); for item in a { - req = req.header(HeaderField::name(), item); + req = req.header(HeaderField::name(), item).take(); } let req = req.finish(); let value = HeaderField::parse(&req); @@ -104,11 +104,11 @@ macro_rules! test_header { #[test] fn $id() { use $crate::test; - + let a: Vec> = $raw.iter().map(|x| x.to_vec()).collect(); let mut req = test::TestRequest::default(); for item in a { - req = req.header(HeaderField::name(), item); + req.header(HeaderField::name(), item); } let req = req.finish(); let val = HeaderField::parse(&req); diff --git a/src/response.rs b/src/response.rs index 807487460..9b503de1b 100644 --- a/src/response.rs +++ b/src/response.rs @@ -4,6 +4,7 @@ use std::{fmt, str}; use bytes::{BufMut, Bytes, BytesMut}; use cookie::{Cookie, CookieJar}; +use futures::future::{ok, FutureResult, IntoFuture}; use futures::Stream; use http::header::{self, HeaderName, HeaderValue}; use http::{Error as HttpError, HeaderMap, HttpTryFrom, StatusCode}; @@ -276,6 +277,16 @@ impl fmt::Debug for Response { } } +impl IntoFuture for Response { + type Item = Response; + type Error = Error; + type Future = FutureResult; + + fn into_future(self) -> Self::Future { + ok(self) + } +} + pub struct CookieIter<'a> { iter: header::ValueIter<'a, HeaderValue>, } @@ -679,6 +690,16 @@ fn parts<'a>( parts.as_mut() } +impl IntoFuture for ResponseBuilder { + type Item = Response; + type Error = Error; + type Future = FutureResult; + + fn into_future(mut self) -> Self::Future { + ok(self.finish()) + } +} + /// Helper converters impl, E: Into> From> for Response { fn from(res: Result) -> Self {