Skip to content

Commit 0efea24

Browse files
mendeltyoshuawuyts
authored andcommitted
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
1 parent 4219851 commit 0efea24

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/endpoint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,6 @@ where
122122
#[async_trait]
123123
impl<State: Clone + Send + Sync + 'static> Endpoint<State> for Box<dyn Endpoint<State>> {
124124
async fn call(&self, request: Request<State>) -> crate::Result {
125-
self.call(request).await
125+
self.as_ref().call(request).await
126126
}
127127
}

tests/endpoint.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use tide::http::{Method, Request, Url};
2+
use tide::Response;
3+
4+
#[async_std::test]
5+
async fn should_accept_boxed_endpoints() {
6+
fn endpoint() -> Box<dyn tide::Endpoint<()>> {
7+
Box::new(|_| async { Ok("hello world") })
8+
}
9+
10+
let mut app = tide::Server::new();
11+
app.at("/").get(endpoint());
12+
13+
let mut response: Response = app
14+
.respond(Request::new(
15+
Method::Get,
16+
Url::parse("http://example.com/").unwrap(),
17+
))
18+
.await
19+
.unwrap();
20+
21+
assert_eq!(
22+
response.take_body().into_string().await.unwrap(),
23+
"hello world"
24+
);
25+
}

0 commit comments

Comments
 (0)