thruster-rs / Thruster

A fast, middleware based, web framework written in Rust
MIT License
1.07k stars 47 forks source link

bug: Method agnostic middleware fails in non root cases #154

Closed trezm closed 4 years ago

trezm commented 4 years ago

Issue: Right now, if you have code that looks like this:

app.use_middleware("/data", async_middleware![some_middleware]);
app.get("/data/:test", async_middleware![endpoint]);

for the request GET /data/asdf, some_middleware will not be called.

Solution: This is because we're comparing the method agnostic routes with method-ful routes. That is, we're comparing /data to __GET__/data/:test. The solution was to artificially ignore those first level of routes when traversing the tree. The root of the agnostic tree will be compared with the second level of the tree with methods.