http-rs / tide

Fast and friendly HTTP server framework for async Rust
https://docs.rs/tide
Apache License 2.0
5.07k stars 321 forks source link

Internal redirects #82

Open aturon opened 6 years ago

aturon commented 6 years ago

Since middleware and endpoints run strictly after routing (by design), we may want to provide an ergonomic way of internally redirecting to other routes.

Some considerations:

aturon commented 6 years ago

cc @wycats

yoshuawuyts commented 4 years ago

We still don't support this currently. Incorrectly closed by #450.

yoshuawuyts commented 4 years ago

A possible API here could be:

async fn endpoint(req: Request<State>) -> tide::Result {
    Ok(req.redirect("/other/route").await?)
}

And then inside the redirect submodule we could implement redirect::internal similar to the other methods for a non-status code based redirect.

As far as the impl goes we should call the router again at the top-level, and then returning the response again. Either we pass a reference to the router along (preferable) or we can pass a bi-directional channel (less preferable).