Show More
@@ -28,6 +28,7 b' import socket' | |||||
28 | import stat |
|
28 | import stat | |
29 |
|
29 | |||
30 | from . import ( |
|
30 | from . import ( | |
|
31 | urllibcompat, | |||
31 | util, |
|
32 | util, | |
32 | ) |
|
33 | ) | |
33 |
|
34 | |||
@@ -214,8 +215,8 b' class FileRangeHandler(urlreq.filehandle' | |||||
214 | server would. |
|
215 | server would. | |
215 | """ |
|
216 | """ | |
216 | def open_local_file(self, req): |
|
217 | def open_local_file(self, req): | |
217 |
host = req |
|
218 | host = urllibcompat.gethost(req) | |
218 |
file = req |
|
219 | file = urllibcompat.getselector(req) | |
219 | localfile = urlreq.url2pathname(file) |
|
220 | localfile = urlreq.url2pathname(file) | |
220 | stats = os.stat(localfile) |
|
221 | stats = os.stat(localfile) | |
221 | size = stats[stat.ST_SIZE] |
|
222 | size = stats[stat.ST_SIZE] | |
@@ -252,7 +253,7 b' class FileRangeHandler(urlreq.filehandle' | |||||
252 |
|
253 | |||
253 | class FTPRangeHandler(urlreq.ftphandler): |
|
254 | class FTPRangeHandler(urlreq.ftphandler): | |
254 | def ftp_open(self, req): |
|
255 | def ftp_open(self, req): | |
255 |
host = req |
|
256 | host = urllibcompat.gethost(req) | |
256 | if not host: |
|
257 | if not host: | |
257 | raise IOError('ftp error', 'no host given') |
|
258 | raise IOError('ftp error', 'no host given') | |
258 | host, port = splitport(host) |
|
259 | host, port = splitport(host) |
@@ -18,6 +18,7 b' from .i18n import _' | |||||
18 | from . import ( |
|
18 | from . import ( | |
19 | httpclient, |
|
19 | httpclient, | |
20 | sslutil, |
|
20 | sslutil, | |
|
21 | urllibcompat, | |||
21 | util, |
|
22 | util, | |
22 | ) |
|
23 | ) | |
23 |
|
24 | |||
@@ -174,13 +175,14 b' class http2handler(urlreq.httphandler, u' | |||||
174 | # object. On Python 2.6.5, it's stored in the _tunnel_host |
|
175 | # object. On Python 2.6.5, it's stored in the _tunnel_host | |
175 | # attribute which has no accessor. |
|
176 | # attribute which has no accessor. | |
176 | tunhost = getattr(req, '_tunnel_host', None) |
|
177 | tunhost = getattr(req, '_tunnel_host', None) | |
177 |
host = req |
|
178 | host = urllibcompat.gethost(req) | |
178 | if tunhost: |
|
179 | if tunhost: | |
179 | proxyhost = host |
|
180 | proxyhost = host | |
180 | host = tunhost |
|
181 | host = tunhost | |
181 | elif req.has_proxy(): |
|
182 | elif req.has_proxy(): | |
182 |
proxyhost = req |
|
183 | proxyhost = urllibcompat.gethost(req) | |
183 | host = req.get_selector().split('://', 1)[1].split('/', 1)[0] |
|
184 | host = urllibcompat.getselector( | |
|
185 | req).split('://', 1)[1].split('/', 1)[0] | |||
184 | else: |
|
186 | else: | |
185 | proxyhost = None |
|
187 | proxyhost = None | |
186 |
|
188 | |||
@@ -219,7 +221,7 b' class http2handler(urlreq.httphandler, u' | |||||
219 | headers = dict( |
|
221 | headers = dict( | |
220 | (name.title(), val) for name, val in headers.items()) |
|
222 | (name.title(), val) for name, val in headers.items()) | |
221 | try: |
|
223 | try: | |
222 |
path = req |
|
224 | path = urllibcompat.getselector(req) | |
223 | if '://' in path: |
|
225 | if '://' in path: | |
224 | path = path.split('://', 1)[1].split('/', 1)[1] |
|
226 | path = path.split('://', 1)[1].split('/', 1)[1] | |
225 | if path[0] != '/': |
|
227 | if path[0] != '/': | |
@@ -233,7 +235,7 b' class http2handler(urlreq.httphandler, u' | |||||
233 | # object initialized properly. |
|
235 | # object initialized properly. | |
234 | r.recv = r.read |
|
236 | r.recv = r.read | |
235 |
|
237 | |||
236 |
resp = urlreq.addinfourl(r, r.headers, req |
|
238 | resp = urlreq.addinfourl(r, r.headers, urllibcompat.getfullurl(req)) | |
237 | resp.code = r.status |
|
239 | resp.code = r.status | |
238 | resp.msg = r.reason |
|
240 | resp.msg = r.reason | |
239 | return resp |
|
241 | return resp | |
@@ -242,7 +244,7 b' class http2handler(urlreq.httphandler, u' | |||||
242 | # target, and then allows full URIs in the request path, which it |
|
244 | # target, and then allows full URIs in the request path, which it | |
243 | # then observes and treats as a signal to do proxying instead. |
|
245 | # then observes and treats as a signal to do proxying instead. | |
244 | def http_open(self, req): |
|
246 | def http_open(self, req): | |
245 |
if req |
|
247 | if urllibcompat.getfullurl(req).startswith('https'): | |
246 | return self.https_open(req) |
|
248 | return self.https_open(req) | |
247 | def makehttpcon(*args, **kwargs): |
|
249 | def makehttpcon(*args, **kwargs): | |
248 | k2 = dict(kwargs) |
|
250 | k2 = dict(kwargs) | |
@@ -251,9 +253,9 b' class http2handler(urlreq.httphandler, u' | |||||
251 | return self.do_open(makehttpcon, req, False) |
|
253 | return self.do_open(makehttpcon, req, False) | |
252 |
|
254 | |||
253 | def https_open(self, req): |
|
255 | def https_open(self, req): | |
254 |
# |
|
256 | # urllibcompat.getfullurl(req) does not contain credentials and we may | |
255 | # need them to match the certificates. |
|
257 | # need them to match the certificates. | |
256 |
url = req |
|
258 | url = urllibcompat.getfullurl(req) | |
257 | user, password = self.pwmgr.find_stored_password(url) |
|
259 | user, password = self.pwmgr.find_stored_password(url) | |
258 | res = readauthforuri(self.ui, url, user) |
|
260 | res = readauthforuri(self.ui, url, user) | |
259 | if res: |
|
261 | if res: |
@@ -93,6 +93,7 b' import threading' | |||||
93 | from .i18n import _ |
|
93 | from .i18n import _ | |
94 | from . import ( |
|
94 | from . import ( | |
95 | pycompat, |
|
95 | pycompat, | |
|
96 | urllibcompat, | |||
96 | util, |
|
97 | util, | |
97 | ) |
|
98 | ) | |
98 |
|
99 | |||
@@ -206,7 +207,7 b' class KeepAliveHandler(object):' | |||||
206 | return self.do_open(HTTPConnection, req) |
|
207 | return self.do_open(HTTPConnection, req) | |
207 |
|
208 | |||
208 | def do_open(self, http_class, req): |
|
209 | def do_open(self, http_class, req): | |
209 |
host = req |
|
210 | host = urllibcompat.gethost(req) | |
210 | if not host: |
|
211 | if not host: | |
211 | raise urlerr.urlerror('no host given') |
|
212 | raise urlerr.urlerror('no host given') | |
212 |
|
213 | |||
@@ -317,10 +318,11 b' class KeepAliveHandler(object):' | |||||
317 | if n in headers: |
|
318 | if n in headers: | |
318 | skipheaders['skip_' + n.replace('-', '_')] = 1 |
|
319 | skipheaders['skip_' + n.replace('-', '_')] = 1 | |
319 | try: |
|
320 | try: | |
320 |
if req |
|
321 | if urllibcompat.hasdata(req): | |
321 |
data = req |
|
322 | data = urllibcompat.getdata(req) | |
322 | h.putrequest( |
|
323 | h.putrequest( | |
323 |
req.get_method(), req |
|
324 | req.get_method(), urllibcompat.getselector(req), | |
|
325 | **skipheaders) | |||
324 | if 'content-type' not in headers: |
|
326 | if 'content-type' not in headers: | |
325 | h.putheader('Content-type', |
|
327 | h.putheader('Content-type', | |
326 | 'application/x-www-form-urlencoded') |
|
328 | 'application/x-www-form-urlencoded') | |
@@ -328,13 +330,14 b' class KeepAliveHandler(object):' | |||||
328 | h.putheader('Content-length', '%d' % len(data)) |
|
330 | h.putheader('Content-length', '%d' % len(data)) | |
329 | else: |
|
331 | else: | |
330 | h.putrequest( |
|
332 | h.putrequest( | |
331 |
req.get_method(), req |
|
333 | req.get_method(), urllibcompat.getselector(req), | |
|
334 | **skipheaders) | |||
332 | except socket.error as err: |
|
335 | except socket.error as err: | |
333 | raise urlerr.urlerror(err) |
|
336 | raise urlerr.urlerror(err) | |
334 | for k, v in headers.items(): |
|
337 | for k, v in headers.items(): | |
335 | h.putheader(k, v) |
|
338 | h.putheader(k, v) | |
336 | h.endheaders() |
|
339 | h.endheaders() | |
337 |
if req |
|
340 | if urllibcompat.hasdata(req): | |
338 | h.send(data) |
|
341 | h.send(data) | |
339 |
|
342 | |||
340 | class HTTPHandler(KeepAliveHandler, urlreq.httphandler): |
|
343 | class HTTPHandler(KeepAliveHandler, urlreq.httphandler): |
@@ -21,6 +21,7 b' from . import (' | |||||
21 | keepalive, |
|
21 | keepalive, | |
22 | pycompat, |
|
22 | pycompat, | |
23 | sslutil, |
|
23 | sslutil, | |
|
24 | urllibcompat, | |||
24 | util, |
|
25 | util, | |
25 | ) |
|
26 | ) | |
26 |
|
27 | |||
@@ -119,7 +120,7 b' class proxyhandler(urlreq.proxyhandler):' | |||||
119 | self.ui = ui |
|
120 | self.ui = ui | |
120 |
|
121 | |||
121 | def proxy_open(self, req, proxy, type_): |
|
122 | def proxy_open(self, req, proxy, type_): | |
122 |
host = req |
|
123 | host = urllibcompat.gethost(req).split(':')[0] | |
123 | for e in self.no_list: |
|
124 | for e in self.no_list: | |
124 | if host == e: |
|
125 | if host == e: | |
125 | return None |
|
126 | return None | |
@@ -166,10 +167,10 b' def _generic_start_transaction(handler, ' | |||||
166 | tunnel_host = 'https://' + tunnel_host |
|
167 | tunnel_host = 'https://' + tunnel_host | |
167 | new_tunnel = True |
|
168 | new_tunnel = True | |
168 | else: |
|
169 | else: | |
169 |
tunnel_host = req |
|
170 | tunnel_host = urllibcompat.getselector(req) | |
170 | new_tunnel = False |
|
171 | new_tunnel = False | |
171 |
|
172 | |||
172 |
if new_tunnel or tunnel_host == req |
|
173 | if new_tunnel or tunnel_host == urllibcompat.getfullurl(req): # has proxy | |
173 | u = util.url(tunnel_host) |
|
174 | u = util.url(tunnel_host) | |
174 | if new_tunnel or u.scheme == 'https': # only use CONNECT for HTTPS |
|
175 | if new_tunnel or u.scheme == 'https': # only use CONNECT for HTTPS | |
175 | h.realhostport = ':'.join([u.host, (u.port or '443')]) |
|
176 | h.realhostport = ':'.join([u.host, (u.port or '443')]) | |
@@ -320,9 +321,9 b' if has_https:' | |||||
320 | return keepalive.KeepAliveHandler._start_transaction(self, h, req) |
|
321 | return keepalive.KeepAliveHandler._start_transaction(self, h, req) | |
321 |
|
322 | |||
322 | def https_open(self, req): |
|
323 | def https_open(self, req): | |
323 |
# |
|
324 | # urllibcompat.getfullurl() does not contain credentials | |
324 | # need them to match the certificates. |
|
325 | # and we may need them to match the certificates. | |
325 |
url = req |
|
326 | url = urllibcompat.getfullurl(req) | |
326 | user, password = self.pwmgr.find_stored_password(url) |
|
327 | user, password = self.pwmgr.find_stored_password(url) | |
327 | res = httpconnectionmod.readauthforuri(self.ui, url, user) |
|
328 | res = httpconnectionmod.readauthforuri(self.ui, url, user) | |
328 | if res: |
|
329 | if res: | |
@@ -406,7 +407,8 b' class httpbasicauthhandler(urlreq.httpba' | |||||
406 | self, auth_header, host, req, headers) |
|
407 | self, auth_header, host, req, headers) | |
407 |
|
408 | |||
408 | def retry_http_basic_auth(self, host, req, realm): |
|
409 | def retry_http_basic_auth(self, host, req, realm): | |
409 |
user, pw = self.passwd.find_user_password( |
|
410 | user, pw = self.passwd.find_user_password( | |
|
411 | realm, urllibcompat.getfullurl(req)) | |||
410 | if pw is not None: |
|
412 | if pw is not None: | |
411 | raw = "%s:%s" % (user, pw) |
|
413 | raw = "%s:%s" % (user, pw) | |
412 | auth = 'Basic %s' % base64.b64encode(raw).strip() |
|
414 | auth = 'Basic %s' % base64.b64encode(raw).strip() |
General Comments 0
You need to be logged in to leave comments.
Login now