@@ -97,8 +97,12 @@ def __init__(self, method, url, *,
97
97
98
98
def update_host (self , url ):
99
99
"""Update destination host, port and connection type (ssl)."""
100
- scheme , netloc , path , query , fragment = \
101
- url_parsed = urllib .parse .urlsplit (url )
100
+ url_parsed = urllib .parse .urlsplit (url )
101
+
102
+ # check for network location part
103
+ netloc = url_parsed .netloc
104
+ if not netloc :
105
+ raise ValueError ('Host could not be detected.' )
102
106
103
107
# get host/port
104
108
host = url_parsed .hostname
@@ -108,9 +112,6 @@ def update_host(self, url):
108
112
raise ValueError (
109
113
'Port number could not be converted.' ) from None
110
114
111
- if not netloc :
112
- raise ValueError ('Host could not be detected.' )
113
-
114
115
# check domain idna encoding
115
116
try :
116
117
netloc = netloc .encode ('idna' ).decode ('utf-8' )
@@ -127,8 +128,10 @@ def update_host(self, url):
127
128
# Record entire netloc for usage in host header
128
129
self .netloc = netloc
129
130
130
- # extract host and port
131
+ scheme = url_parsed . scheme
131
132
self .ssl = scheme == 'https'
133
+
134
+ # set port number if it isn't already set
132
135
if not port :
133
136
if self .ssl :
134
137
port = HTTPS_PORT
0 commit comments