Skip to content

Commit

Permalink
Merge pull request #94 from oddstr13/pr-address-normalize-1
Browse files Browse the repository at this point in the history
Improve address normalization in connection manager
  • Loading branch information
oddstr13 authored Sep 28, 2019
2 parents d7cc0a4 + 0f81a08 commit ad14005
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions resources/lib/jellyfin/core/connection_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

import json
import logging
import hashlib
import socket
import time
from datetime import datetime
from distutils.version import LooseVersion

import urllib3

from credentials import Credentials
from http import HTTP

Expand Down Expand Up @@ -109,7 +110,7 @@ def login(self, server, username, password=None, clear=True, options={}):

if not server:
raise AttributeError("server cannot be empty")

try:
request = {
'type': "POST",
Expand All @@ -134,6 +135,8 @@ def connect_to_address(self, address, options={}):
if not address:
return False

address = self._normalize_address(address)

def _on_fail():
LOG.error("connectToAddress %s failed", address)
return self._resolve_failure()
Expand Down Expand Up @@ -470,13 +473,18 @@ def _convert_endpoint_address_to_manual_address(self, info):

def _normalize_address(self, address):
# Attempt to correct bad input
address = address.strip()
address = address.lower()
url = urllib3.util.parse_url(address.strip())

if url.scheme is None:
url = url._replace(scheme='http')

if url.scheme == 'http' and url.port == 80:
url = url._replace(port=None)

if 'http' not in address:
address = "http://%s" % address
if url.scheme == 'https' and url.port == 443:
url = url._replace(port=None)

return address
return url.url

def _save_user_info_into_credentials(self, server, user):

Expand Down

0 comments on commit ad14005

Please sign in to comment.