##// END OF EJS Templates
http: use urllib's cookie handler...
Joerg Sonnenberger -
r52723:20869811 default
parent child Browse files
Show More
@@ -455,41 +455,25 b' class httpbasicauthhandler(urlreq.httpba'
455 return None
455 return None
456
456
457
457
458 class cookiehandler(urlreq.basehandler):
458 def load_cookiejar(ui):
459 def __init__(self, ui):
459 cookiefile = ui.config(b'auth', b'cookiefile')
460 self.cookiejar = None
460 if not cookiefile:
461
461 return
462 cookiefile = ui.config(b'auth', b'cookiefile')
462 cookiefile = util.expandpath(cookiefile)
463 if not cookiefile:
463 try:
464 return
464 cookiejar = util.cookielib.MozillaCookieJar(
465
465 pycompat.fsdecode(cookiefile)
466 cookiefile = util.expandpath(cookiefile)
466 )
467 try:
467 cookiejar.load()
468 cookiejar = util.cookielib.MozillaCookieJar(
468 return cookiejar
469 pycompat.fsdecode(cookiefile)
469 except util.cookielib.LoadError as e:
470 ui.warn(
471 _(
472 b'(error loading cookie file %s: %s; continuing without '
473 b'cookies)\n'
470 )
474 )
471 cookiejar.load()
475 % (cookiefile, stringutil.forcebytestr(e))
472 self.cookiejar = cookiejar
476 )
473 except util.cookielib.LoadError as e:
474 ui.warn(
475 _(
476 b'(error loading cookie file %s: %s; continuing without '
477 b'cookies)\n'
478 )
479 % (cookiefile, stringutil.forcebytestr(e))
480 )
481
482 def http_request(self, request):
483 if self.cookiejar:
484 self.cookiejar.add_cookie_header(request)
485
486 return request
487
488 def https_request(self, request):
489 if self.cookiejar:
490 self.cookiejar.add_cookie_header(request)
491
492 return request
493
477
494
478
495 class readlinehandler(urlreq.basehandler):
479 class readlinehandler(urlreq.basehandler):
@@ -575,7 +559,7 b' def opener('
575 (httpbasicauthhandler(passmgr), httpdigestauthhandler(passmgr))
559 (httpbasicauthhandler(passmgr), httpdigestauthhandler(passmgr))
576 )
560 )
577 handlers.extend([h(ui, passmgr) for h in handlerfuncs])
561 handlers.extend([h(ui, passmgr) for h in handlerfuncs])
578 handlers.append(cookiehandler(ui))
562 handlers.append(urlreq.httpcookieprocessor(cookiejar=load_cookiejar(ui)))
579 handlers.append(readlinehandler())
563 handlers.append(readlinehandler())
580 opener = urlreq.buildopener(*handlers)
564 opener = urlreq.buildopener(*handlers)
581
565
@@ -68,6 +68,7 b' urlreq._registeraliases('
68 b"FileHandler",
68 b"FileHandler",
69 b"FTPHandler",
69 b"FTPHandler",
70 b"ftpwrapper",
70 b"ftpwrapper",
71 b"HTTPCookieProcessor",
71 b"HTTPHandler",
72 b"HTTPHandler",
72 b"HTTPSHandler",
73 b"HTTPSHandler",
73 b"install_opener",
74 b"install_opener",
General Comments 0
You need to be logged in to leave comments. Login now