klein icon indicating copy to clipboard operation
klein copied to clipboard

allow for "overlay" routing

Open glyph opened this issue 10 years ago • 2 comments

Sometimes I have a structure like this:

@route("/a/", branch=True)
def some_tree(request):
    return static.File("...")

@route("/a/foo/bar/special_thing.txt")
def some_overlaid_resource(request):
    return EventSource(...)

I'd really like that second route to show up if that specific route is requested, but the first to take over for everything else within that hierarchy.

Probably this is a bug in Werkzeug, but I am experiencing it with Klein so I'm starting here.

glyph avatar Feb 10 '15 23:02 glyph

Okay wait a second maybe this already works if you put @route("/a/foo/bar/special_thing.txt") first? I can't tell if I'm depending on some accident of hash ordering or something like that..

glyph avatar Feb 10 '15 23:02 glyph

I'd strongly suspect that this is Werkzeug being funky. From https://github.com/mitsuhiko/werkzeug/blob/2b2d921eea7d1f896ce436ec5238890abe8b81bf/werkzeug/routing.py#L855 :

Current implementation:

  1. rules without any arguments come first for performance reasons only as we expect them to match faster and some common ones usually don't have any arguments (index pages etc.)
  2. The more complex rules come first so the second argument is the negative length of the number of weights.
  3. lastly we order by the actual weights.

brighid avatar Sep 09 '15 05:09 brighid