diff options
author | Lekinho <mctreasure@gmail.com> | 2020-02-12 06:29:31 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-12 10:29:31 +0000 |
commit | c8de203b0dec88c65a32e2d1edb2480644dfbc84 (patch) | |
tree | c07900c15cfab46be6177092480c827f390afd61 /paste | |
parent | 177f22e80b2ecde710a5423ab12db5280bdff3eb (diff) | |
download | paste-git-c8de203b0dec88c65a32e2d1edb2480644dfbc84.tar.gz |
add ipv6 support by setting address family (#50)
* add ipv6 support by setting address family
Diffstat (limited to 'paste')
-rwxr-xr-x | paste/httpserver.py | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/paste/httpserver.py b/paste/httpserver.py index 79468f3..0cfe6c2 100755 --- a/paste/httpserver.py +++ b/paste/httpserver.py @@ -1289,13 +1289,39 @@ def serve(application, host=None, port=None, handler=None, ssl_pem=None, ssl_context.use_certificate_chain_file(ssl_pem) host = host or '127.0.0.1' + is_ipv6 = False + if host.count(':') > 1 or '[' in host : + is_ipv6 = True + if port is None: - if ':' in host: + + if ':' in host and is_ipv6 is False: host, port = host.split(':', 1) + elif is_ipv6 and ']' in host: + + idx = host.find(']') + if (idx < (len(host) - 1)) and (host[(idx+1)] == ':'): + # check if the next position is ':', if so, split and grab the port + + host, port = host.rsplit(':', 1) + host = host.strip('[').strip(']') + + else : + + port = 8080 else: + port = 8080 + #strip '[' and ']' in host + host = host.strip('[').strip(']') server_address = (host, int(port)) + if is_ipv6: + # set address family + HTTPServer.address_family = socket.AF_INET6 + else: + HTTPServer.address_family = socket.AF_INET + if not handler: handler = WSGIHandler if server_version: |