You already have this code, but as part of cowboy_rest.
I want to use it in none rest handler.
It's will be great if you move logic of prioritized choosing some where, where users can use it.
The problem is that they're inline, they don't return anything. I can't really move them without losing the optimization.