]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Make add_handlers (for multiple hostnames) usable with static_path (which
authorBen Darnell <bdarnell@beaker.local>
Fri, 26 Mar 2010 22:55:04 +0000 (15:55 -0700)
committerBen Darnell <bdarnell@beaker.local>
Fri, 26 Mar 2010 22:55:04 +0000 (15:55 -0700)
forces the creation of a wildcard handler) by maintaining a sensible order
for handler groups.

tornado/web.py

index 4fa2aa301ca8836448ed3a8909c4ecac1506fd7c..072b261c40d1db5ca9fc7f6600954fa1252ab89e 100644 (file)
@@ -934,7 +934,15 @@ class Application(object):
         if not host_pattern.endswith("$"):
             host_pattern += "$"
         handlers = []
-        self.handlers.append((re.compile(host_pattern), handlers))
+        # The handlers with the wildcard host_pattern are a special
+        # case - they're added in the constructor but should have lower
+        # precedence than the more-precise handlers added later.
+        # If a wildcard handler group exists, it should always be last
+        # in the list, so insert new groups just before it.
+        if self.handlers and self.handlers[-1][0].pattern == '.*$':
+            self.handlers.insert(-1, (re.compile(host_pattern), handlers))
+        else:
+            self.handlers.append((re.compile(host_pattern), handlers))
 
         for spec in host_handlers:
             if type(spec) is type(()):