mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-12-26 02:36:10 +00:00
Improve address normalization in connection manager
This commit is contained in:
parent
94b8fe85dc
commit
0f81a080a8
1 changed files with 15 additions and 7 deletions
|
@ -4,12 +4,13 @@
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import hashlib
|
|
||||||
import socket
|
import socket
|
||||||
import time
|
import time
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from distutils.version import LooseVersion
|
from distutils.version import LooseVersion
|
||||||
|
|
||||||
|
import urllib3
|
||||||
|
|
||||||
from credentials import Credentials
|
from credentials import Credentials
|
||||||
from http import HTTP
|
from http import HTTP
|
||||||
|
|
||||||
|
@ -134,6 +135,8 @@ class ConnectionManager(object):
|
||||||
if not address:
|
if not address:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
address = self._normalize_address(address)
|
||||||
|
|
||||||
def _on_fail():
|
def _on_fail():
|
||||||
LOG.error("connectToAddress %s failed", address)
|
LOG.error("connectToAddress %s failed", address)
|
||||||
return self._resolve_failure()
|
return self._resolve_failure()
|
||||||
|
@ -470,13 +473,18 @@ class ConnectionManager(object):
|
||||||
|
|
||||||
def _normalize_address(self, address):
|
def _normalize_address(self, address):
|
||||||
# Attempt to correct bad input
|
# Attempt to correct bad input
|
||||||
address = address.strip()
|
url = urllib3.util.parse_url(address.strip())
|
||||||
address = address.lower()
|
|
||||||
|
|
||||||
if 'http' not in address:
|
if url.scheme is None:
|
||||||
address = "http://%s" % address
|
url = url._replace(scheme='http')
|
||||||
|
|
||||||
return address
|
if url.scheme == 'http' and url.port == 80:
|
||||||
|
url = url._replace(port=None)
|
||||||
|
|
||||||
|
if url.scheme == 'https' and url.port == 443:
|
||||||
|
url = url._replace(port=None)
|
||||||
|
|
||||||
|
return url.url
|
||||||
|
|
||||||
def _save_user_info_into_credentials(self, server, user):
|
def _save_user_info_into_credentials(self, server, user):
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue