diff --git a/src/context.rs b/src/context.rs index aaf1c5b3a..1ff7f00bc 100644 --- a/src/context.rs +++ b/src/context.rs @@ -54,11 +54,6 @@ impl Context { &self.request } - /// Mutably access the request body - pub fn body(&mut self) -> &mut http_service::Body { - self.request.body_mut() - } - /// Access app-global data. pub fn app_data(&self) -> &AppData { &self.app_data diff --git a/src/cookies.rs b/src/cookies.rs index 7a2695884..c5f67ee6b 100644 --- a/src/cookies.rs +++ b/src/cookies.rs @@ -24,7 +24,7 @@ impl ExtractCookies for Context { .unwrap_or_else(|| CookieData { content: self .headers() - .get("Cookie") + .get("tide-cookie") .and_then(|raw| parse_from_header(raw.to_str().unwrap()).ok()) .unwrap_or_default(), }); diff --git a/src/endpoint.rs b/src/endpoint.rs index bbfbedc08..2333f00f2 100644 --- a/src/endpoint.rs +++ b/src/endpoint.rs @@ -1,5 +1,4 @@ use futures::future::{Future, FutureObj}; -use std::pin::Pin; use crate::{response::IntoResponse, Context, Response}; @@ -49,26 +48,11 @@ where Fut: Future + Send + 'static, Fut::Output: IntoResponse, { - type Fut = ResponseWrapper; + type Fut = FutureObj<'static, Response>; fn call(&self, cx: Context) -> Self::Fut { - ResponseWrapper { fut: (self)(cx) } - } -} - -/// The future retured by the endpoint implementation for `Fn` types. -pub struct ResponseWrapper { - fut: F, -} - -impl Future for ResponseWrapper -where - F: Future, - F::Output: IntoResponse, -{ - type Output = Response; - - fn poll(self: Pin<&mut Self>, waker: &std::task::Waker) -> std::task::Poll { - let inner = unsafe { self.map_unchecked_mut(|wrapper| &mut wrapper.fut) }; - inner.poll(waker).map(IntoResponse::into_response) + let fut = (self)(cx); + box_async! { + await!(fut).into_response() + } } } diff --git a/src/error.rs b/src/error.rs index 4daeab999..8999eac9e 100644 --- a/src/error.rs +++ b/src/error.rs @@ -74,6 +74,18 @@ pub trait ResultExt: Sized { StatusCode: HttpTryFrom; } +/// Extends the `Response` type with a method to extract error causes when applicable. +pub trait ResponseExt { + /// Extract the cause of the unsuccessful response, if any + fn err_cause(&self) -> Option<&(dyn std::error::Error + Send + Sync + 'static)>; +} + +impl ResponseExt for Response { + fn err_cause(&self) -> Option<&(dyn std::error::Error + Send + Sync + 'static)> { + self.extensions().get().map(|Cause(c)| &**c) + } +} + impl ResultExt for std::result::Result { fn with_err_status(self, status: S) -> EndpointResult where