'Overwrites proxyClientFactoryClass to add a TLS wrapper to all
connections generated by ReverseProxyResource protocol factory
if enabled.'

def proxyClientFactoryClass(self, *args, **kwargs):

    client_factory = HTTPProxyClientFactory(*args, **kwargs)
    if self.__ssl_enabled:
        with open(server.config.ssl.certificate) as cert_file:
            cert = ssl.Certificate.loadPEM(cert_file.read())
        return TLSMemoryBIOFactory(ssl.optionsForClientTLS(self.host.decode('ascii'), cert), isClient=True, wrappedFactory=client_factory)
    else:
        return client_factory
