netcache: add support for IPv6 hostname bug #40

This commit is contained in:
Ploum 2024-02-15 22:59:27 +01:00
parent d427287784
commit 4e3d3ce62d
2 changed files with 4 additions and 1 deletions

View File

@ -1,7 +1,7 @@
# Offpunk History
## 2.3 - Unreleased
- offpunk: fix IPv6 as an URL (bug #40)
- offpunk/netcache: fix IPv6 as an URL (bug #40)
## 2.2 - February 13th 2023
- cache folder is now configurable through $OFFPUNK_CACHE_PATH environment variable (by prx)

View File

@ -656,6 +656,9 @@ def _fetch_gemini(url,timeout=DEFAULT_TIMEOUT,interactive=True,accept_bad_ssl_ce
# Send request and wrap response in a file descriptor
url = urllib.parse.urlparse(url)
new_netloc = host
#Handle IPV6 hostname
if ":" in new_netloc:
new_netloc = "[" + new_netloc + "]"
if port != standard_ports["gemini"]:
new_netloc += ":" + str(port)
url = urllib.parse.urlunparse(url._replace(netloc=new_netloc))