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

Bad route selection based on acceptType. #1077

Open folarte opened 5 years ago

folarte commented 5 years ago

I did a test with .

get("/mypath","application/json", MyRoute)

and got my document when acceptin app/json or / with curl. But I got a 404 when accepting text/html. I wanted to get 406 - Not accepted ( simplifies debugging my clients, I know failure is in the accept header ), so I built an H406 route which just does "throw halt(406)" and added

get("/mypath",H406)

AFTER the previous. As the documentation states routes are processed in order I expected it to match anything not catched. Testing I got 406 for text/html and 200+doc for app/json, but for the default '*/*' used by curl for accept I got the 406 too. I was expecting for it to match the first route, Then I went into jedi mode and used the source, and found a route without acceptType gets registered as */*, and the mime parser matches it as preferrable to the first one because it matches exactly with what the client sends.

I'm not familiar enough with spark to assert it is a bug, but I consider this as either a code bug or a documentation one, as I suspect many people will interpret the docs as I did.

( Not a big problem as it can be easily patched or coded around, and not sure of my source analysis being a spark novice. )

Chauncey-Xxy commented 3 years ago

I am not sure whether it is a bug, but I think it may conflict with the documentation . So I will try to fix this issue.