'Create connection for the request.'

def get_connection(self, request):

    protocol = (request.protocol_override if request.protocol_override else self.protocol)
    protocol = protocol.lower()
    target_host = request.host
    target_port = (HTTP_PORT if (protocol == 'http') else HTTPS_PORT)
    if self.request_session:
        from .requestsclient import _RequestsConnection
        connection = _RequestsConnection(target_host, protocol, self.request_session, self.timeout)
        proxy_host = self.proxy_host
        proxy_port = self.proxy_port
    else:
        from .winhttp import _HTTPConnection
        connection = _HTTPConnection(target_host, self.cert_file, protocol, self.timeout)
        proxy_host = self.proxy_host
        proxy_port = self.proxy_port
    if self.proxy_host:
        headers = None
        if (self.proxy_user and self.proxy_password):
            auth = base64.encodestring('{0}:{1}'.format(self.proxy_user, self.proxy_password).encode()).rstrip()
            headers = {'Proxy-Authorization': 'Basic    {0}'.format(auth.decode())}
        connection.set_tunnel(proxy_host, int(proxy_port), headers)
    return connection
