From 0bd86f77293e8d118291f31ab66a3e3ac110c47f Mon Sep 17 00:00:00 2001 From: Benoit Chesneau Date: Sun, 30 Jan 2011 18:46:17 +0100 Subject: [PATCH] fix ipv6 address parsing in forward address. Spotted 3 weeks ago by Jonathan Leroy. --- gunicorn/http/wsgi.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/gunicorn/http/wsgi.py b/gunicorn/http/wsgi.py index e8cf8ea8..0302eed3 100644 --- a/gunicorn/http/wsgi.py +++ b/gunicorn/http/wsgi.py @@ -77,9 +77,22 @@ def create(req, sock, client, server, cfg): # http://en.wikipedia.org/wiki/X-Forwarded-For if forward.find(",") >= 0: forward = forward.rsplit(",", 1)[1].strip() - remote = forward.split(":") - if len(remote) < 2: - remote.append('80') + + # find host and port on ipv6 address + if '[' in forward and ']' in forward: + host = forward.split(']')[0][1:].lower() + elif ":" in forward: + host = forward.split(":")[0].lower() + else: + host = fowerd + + forward = forward.split(']')[-1] + if ":" in forward: + port = forward.split(':', 1)[1] + else: + port = 80 + + remote = (host, port) else: remote = forward