robjtede / actix-web-lab

Experimental extractors, middleware, and other extras for possible inclusion in Actix Web.
Apache License 2.0
98 stars 14 forks source link

Dynamic redirecting #37

Open letto4135 opened 2 years ago

letto4135 commented 2 years ago

The docs show that you can do this

// redirects "/oh/hi/mark" to "/oh/bye/mark"
Redirect::new("/oh/hi/mark", "../../bye/mark");

A nice thing to be able to do would be would be more dynamic redirects. Examples:

// redirects "/redirect/me/to/here" to "https://hello.com/me/to/here"
Redirect::new("/redirect", "https://hello.com/../../..")
// redirects "/redirectme/tohere" to https://hello.com/tohere"
Redirect::new("/redirectme", "https://hello.com/..")
// redirects /redirect/me/to/here to "https://hello.com/redirect/me/to/here"
Redirect::new("/redirectme", "https://hello.com/**")
robjtede commented 2 years ago

The redirect service does not pattern match.

The example:

Redirect::new("/oh/hi/mark", "../../bye/mark");

literally sends the header Location: ../../bye/mark back to the client. It is up to them to resolve this and make the follow-up request.

I can see the use case for a more dynamic redirect system that does match patterns. If this is what you are looking for, I'd suggest re-wording the issue and we can turn this into a feature request.

Regarding preserving body, it is irrelevant because this is not intended to be a proxy. It only serves redirect responses.