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.64k stars 1.56k forks source link

route matching with wildcard with multiple slashes is not working #945

Open bagipriyank opened 6 years ago

bagipriyank commented 6 years ago

get("/say/*/to/*", (request, response) -> request.splat()[0] + " " + request.splat()[1]);

if you pass /say/good/golly/miss/molly/to/luka it doesn't work. Instead of request.splat()[0] mapping to good/golly/miss/molly and request.splat()[1] mapping to luka i get a 404.

tipsy commented 6 years ago

Are you expecting request.splat()[0] -> good/golly/miss/molly request.splat()[1] -> luka

?

bagipriyank commented 6 years ago

yes. that's what i expected after i saw https://github.com/perwendel/spark/issues/59#issuecomment-239677100

bagipriyank commented 6 years ago

i see the issue is happening because of no backtracking while matching routes with wildcards.

https://github.com/perwendel/spark/blob/1ecd428c8e2e5b0d1b8f221e9bf9e82429bd73bb/src/main/java/spark/route/RouteEntry.java#L86

Is this behavior intended?

bagipriyank commented 6 years ago

the bigger problem is that /say/good/golly/miss/molly/to/luka doesn't map to /say/*/to/*

tipsy commented 6 years ago

I don't think it's intended, maybe @perwendel knows? I've marked it as a bug at least.

bagipriyank commented 6 years ago

created https://github.com/perwendel/spark/pull/950/ to resolve this. please have a look.

bagipriyank commented 6 years ago

any news on this? :)

bagipriyank commented 6 years ago

any progress on this?

bagipriyank commented 6 years ago

any update on this?

vladp commented 6 years ago

Hello

is @bagipriyank fix not merged due to issues with the pull, or just maintainer's capacity ?

thank you

perwendel commented 5 years ago

@bagipriyank I find this pretty weird. I get what the purpose is and how it would work but I can't imagine why or when anyone would use URLs this way but I might be ignorant of the potenial use-cases.

perwendel commented 5 years ago

@bagipriyank however, after looking at the discussion in #59 I understand a bit better. I'm still very interested in a use case where this would be useful so I can learn something.

bagipriyank commented 5 years ago

@perwendel one place where we are using this is in our image processing service. we send the link to original images to the client, and then depending on what experience client is showing it can apply image processing commands and send a request to the server to generate the final image on the fly.

ex endpoint:

Spark.get("/idType/:idType/context/:context/id/:id/*/filters/*", processImage);
Spark.get("/*/filters/*", processImage);

ex requests

1. https://images.com/idType/a/context/homepage/id/b/flowers/sunflower.png/filters/blur
2. https://images.com/idType/a/context/homepage/id/b/https://flowers.com/hd/sunflower.png/filters/blur
3. https://images.com/flowers/sunflower.png/filters/blur
4. https://images.com/https://flowers.com/hd/sunflower.png/filters/blur

here splat[0] = flowers/sunflower.png for 1 and 3 and splat[0] = https://flowers.com/hd/sunflower.png for 2 and 4

we could have definitely tried extracting these things ourselves with in processImage method but this approach makes it much more cleaner

bagipriyank commented 4 years ago

@perwendel any update on this?