Skip to content

Commit dc28fd5

Browse files
committed
Follow up to #156
1 parent 7a9519a commit dc28fd5

File tree

4 files changed

+18
-27
lines changed

4 files changed

+18
-27
lines changed

src/context.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,6 @@ impl<AppData> Context<AppData> {
5454
&self.request
5555
}
5656

57-
/// Mutably access the request body
58-
pub fn body(&mut self) -> &mut http_service::Body {
59-
self.request.body_mut()
60-
}
61-
6257
/// Access app-global data.
6358
pub fn app_data(&self) -> &AppData {
6459
&self.app_data

src/cookies.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ impl<AppData> ExtractCookies for Context<AppData> {
2424
.unwrap_or_else(|| CookieData {
2525
content: self
2626
.headers()
27-
.get("Cookie")
27+
.get("tide-cookie")
2828
.and_then(|raw| parse_from_header(raw.to_str().unwrap()).ok())
2929
.unwrap_or_default(),
3030
});

src/endpoint.rs

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use futures::future::{Future, FutureObj};
2-
use std::pin::Pin;
32

43
use crate::{response::IntoResponse, Context, Response};
54

@@ -49,26 +48,11 @@ where
4948
Fut: Future + Send + 'static,
5049
Fut::Output: IntoResponse,
5150
{
52-
type Fut = ResponseWrapper<Fut>;
51+
type Fut = FutureObj<'static, Response>;
5352
fn call(&self, cx: Context<AppData>) -> Self::Fut {
54-
ResponseWrapper { fut: (self)(cx) }
55-
}
56-
}
57-
58-
/// The future retured by the endpoint implementation for `Fn` types.
59-
pub struct ResponseWrapper<F> {
60-
fut: F,
61-
}
62-
63-
impl<F> Future for ResponseWrapper<F>
64-
where
65-
F: Future,
66-
F::Output: IntoResponse,
67-
{
68-
type Output = Response;
69-
70-
fn poll(self: Pin<&mut Self>, waker: &std::task::Waker) -> std::task::Poll<Response> {
71-
let inner = unsafe { self.map_unchecked_mut(|wrapper| &mut wrapper.fut) };
72-
inner.poll(waker).map(IntoResponse::into_response)
53+
let fut = (self)(cx);
54+
box_async! {
55+
await!(fut).into_response()
56+
}
7357
}
7458
}

src/error.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,18 @@ pub trait ResultExt<T>: Sized {
7474
StatusCode: HttpTryFrom<S>;
7575
}
7676

77+
/// Extends the `Response` type with a method to extract error causes when applicable.
78+
pub trait ResponseExt {
79+
/// Extract the cause of the unsuccessful response, if any
80+
fn err_cause(&self) -> Option<&(dyn std::error::Error + Send + Sync + 'static)>;
81+
}
82+
83+
impl<T> ResponseExt for Response<T> {
84+
fn err_cause(&self) -> Option<&(dyn std::error::Error + Send + Sync + 'static)> {
85+
self.extensions().get().map(|Cause(c)| &**c)
86+
}
87+
}
88+
7789
impl<T, E: std::error::Error + Send + Sync + 'static> ResultExt<T> for std::result::Result<T, E> {
7890
fn with_err_status<S>(self, status: S) -> EndpointResult<T>
7991
where

0 commit comments

Comments
 (0)