"""Reload trust and the current client leaf for every network connection.""" import urllib3 from urllib3.connection import HTTPSConnection from urllib3.connectionpool import HTTPSConnectionPool from src import identity class CurrentConnection(HTTPSConnection): def connect(self): self.ssl_context = identity.tls_context() self.cert_reqs = "CERT_REQUIRED" return super().connect() class CurrentPool(HTTPSConnectionPool): ConnectionCls = CurrentConnection def pool(**kwargs): manager = urllib3.PoolManager(**kwargs) # Copy before changing: PoolManager otherwise shares the class mapping. manager.pool_classes_by_scheme = dict(manager.pool_classes_by_scheme) manager.pool_classes_by_scheme["https"] = CurrentPool return manager