perwendel / spark

A simple expressive web framework for java. Spark has a kotlin DSL https://github.com/perwendel/spark-kotlin
Apache License 2.0
9.65k stars 1.56k forks source link

redirect to add trailing slash #1056

Open zd-project opened 6 years ago

zd-project commented 6 years ago

http://sparkjava.com/documentation#redirects, method doesn't seem to work when I try to add the trailing slash, e.g.,

path("/url", () -> {
    redirect.get("", "/");
    get("/", ...);
});

Server fails to recognize the redirect. It confuses me because it seems under the hood redirect.get calls the same helper functions get calls.

I'm able to get away with this. https://stackoverflow.com/questions/34753001/spark-framework-match-with-or-without-trailing-slash

Can anyone give some explanations?

tipsy commented 6 years ago

I'm not sure redirect works within path.

zd-project commented 6 years ago

What is the design decision behind this? It sounds counterintuitive to me if it doesn't support path

tipsy commented 6 years ago

It's more of a bug than a design decision (if it doesn't).

zd-project commented 6 years ago

It looks to me the pattern matching algorithm might be the reason. I don't understand why it's the case but the path regex has to start with a slash, e.g., "/*". Otherwise the bug occurs. I remember I read about this in some other posts as well.