]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
fix matching a IPv6 address as host
author依云 <lilydjwg@gmail.com>
Tue, 25 Nov 2014 13:36:28 +0000 (21:36 +0800)
committer依云 <lilydjwg@gmail.com>
Tue, 25 Nov 2014 13:41:02 +0000 (21:41 +0800)
When the host is something like '[::1]' or '[::1]:8080',
_get_host_handlers gets wrong hosts string.

tornado/web.py

index a038265fd3fd4a726d8e1f2f993c79dc9e5ab1e7..78ab1faf642651d3b16a2047b6da84a7269b6cf3 100644 (file)
@@ -1729,7 +1729,9 @@ class Application(httputil.HTTPServerConnectionDelegate):
         self.transforms.append(transform_class)
 
     def _get_host_handlers(self, request):
-        host = request.host.lower().split(':')[0]
+        host = request.host.lower()
+        if not host.endswith(']'): # excluding IPv6 addresses without port
+            host = host.rsplit(':', 1)[0]
         matches = []
         for pattern, handlers in self.handlers:
             if pattern.match(host):