mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
IPv6 requires [] for host:port style notation
ex) IPv4: 127.0.0.1:8080 IPv6: [::1]:8080
This commit is contained in:
parent
d4b52a0098
commit
080e61d128
@ -16,10 +16,22 @@ from calibre.utils.smtp import config as email_config
|
||||
|
||||
|
||||
def local_url_for_content_server():
|
||||
def is_ipv6_addr(addr):
|
||||
import socket
|
||||
try:
|
||||
socket.inet_pton(socket.AF_INET6, addr)
|
||||
return True
|
||||
except OSError:
|
||||
return False
|
||||
|
||||
from calibre.srv.opts import server_config
|
||||
opts = server_config()
|
||||
interface = opts.listen_on or '0.0.0.0'
|
||||
interface = {'0.0.0.0': '127.0.0.1', '::':'::1'}.get(interface)
|
||||
|
||||
if is_ipv6_addr(interface):
|
||||
interface = f'[{interface}]'
|
||||
|
||||
protocol = 'https' if opts.ssl_certfile and opts.ssl_keyfile else 'http'
|
||||
prefix = opts.url_prefix or ''
|
||||
port = opts.port
|
||||
|
@ -1299,10 +1299,22 @@ class ConfigWidget(ConfigWidgetBase):
|
||||
self.stopping_msg.accept()
|
||||
|
||||
def test_server(self):
|
||||
def is_ipv6_addr(addr):
|
||||
import socket
|
||||
try:
|
||||
socket.inet_pton(socket.AF_INET6, addr)
|
||||
return True
|
||||
except OSError:
|
||||
return False
|
||||
|
||||
prefix = self.advanced_tab.get('url_prefix') or ''
|
||||
protocol = 'https' if self.advanced_tab.has_ssl else 'http'
|
||||
lo = self.advanced_tab.get('listen_on') or '0.0.0.0'
|
||||
lo = {'0.0.0.0': '127.0.0.1', '::':'::1'}.get(lo)
|
||||
|
||||
if is_ipv6_addr(lo):
|
||||
lo = f'[{lo}]'
|
||||
|
||||
url = '{protocol}://{interface}:{port}{prefix}'.format(
|
||||
protocol=protocol, interface=lo,
|
||||
port=self.main_tab.opt_port.value(), prefix=prefix)
|
||||
|
Loading…
x
Reference in New Issue
Block a user