Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

Make add_handlers (for multiple hostnames) usable with static_path (w…


forces the creation of a wildcard handler) by maintaining a sensible order
for handler groups.
  • Loading branch information...
commit a4ba918180ca292cc2f67a6793c8563cec0d1ac3 1 parent 6326f82
Ben Darnell authored
Showing with 9 additions and 1 deletion.
  1. +9 −1 tornado/
10 tornado/
@@ -934,7 +934,15 @@ def add_handlers(self, host_pattern, host_handlers):
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(()):

0 comments on commit a4ba918

Please sign in to comment.
Something went wrong with that request. Please try again.