From e894754e10d2e8017e67bb105c840c6eec80b382 Mon Sep 17 00:00:00 2001 From: Mendelt Siebenga Date: Thu, 1 Oct 2020 21:24:44 +0200 Subject: [PATCH] Fix a missing as_ref that caused boxed endpoints to enter an infinite loop I also added a test for this that shows it now works. thanks to Hasali19 for noticing this --- src/endpoint.rs | 2 +- tests/endpoint.rs | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 tests/endpoint.rs diff --git a/src/endpoint.rs b/src/endpoint.rs index 5931a40e3..48b08c0c6 100644 --- a/src/endpoint.rs +++ b/src/endpoint.rs @@ -122,6 +122,6 @@ where #[async_trait] impl Endpoint for Box> { async fn call(&self, request: Request) -> crate::Result { - self.call(request).await + self.as_ref().call(request).await } } diff --git a/tests/endpoint.rs b/tests/endpoint.rs new file mode 100644 index 000000000..7d376997a --- /dev/null +++ b/tests/endpoint.rs @@ -0,0 +1,25 @@ +use tide::http::{Method, Request, Url}; +use tide::Response; + +#[async_std::test] +async fn should_accept_boxed_endpoints() { + fn endpoint() -> Box> { + Box::new(|_| async { Ok("hello world") }) + } + + let mut app = tide::Server::new(); + app.at("/").get(endpoint()); + + let mut response: Response = app + .respond(Request::new( + Method::Get, + Url::parse("http://example.com/").unwrap(), + )) + .await + .unwrap(); + + assert_eq!( + response.take_body().into_string().await.unwrap(), + "hello world" + ); +}