From: 依云 Date: Tue, 25 Nov 2014 13:36:28 +0000 (+0800) Subject: fix matching a IPv6 address as host X-Git-Tag: v4.1.0b1~49^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=36b35653b175d1866a7ba5dacf7b69177d49872a;p=thirdparty%2Ftornado.git fix matching a IPv6 address as host When the host is something like '[::1]' or '[::1]:8080', _get_host_handlers gets wrong hosts string. --- diff --git a/tornado/web.py b/tornado/web.py index a038265fd..78ab1faf6 100644 --- a/tornado/web.py +++ b/tornado/web.py @@ -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):