def get_connection(self, request):
protocol = request.protocol_overrideif request.protocol_override else self.protocol<EOL>protocol = protocol.lower()<EOL>target_host = request.host<EOL>target_port = HTTP_PORT if protocol == '<STR_LIT:http>' else HTTPS_PORT<EOL>connection = _RequestsConnection(<EOL>target_host, protocol, self.request_session, self.timeout)<EOL>proxy_host = self.proxy_host<EOL>proxy_port = self.proxy_port<EOL>if self.proxy_host:<EOL><INDENT>headers = None<EOL>if self.proxy_user and self.proxy_password:<EOL><INDENT>auth = base64.encodestring(<EOL>"<STR_LIT>".format(self.proxy_user, self.proxy_password).encode()).rstrip()<EOL>headers = {'<STR_LIT>': '<STR_LIT>'.format(auth.decode())}<EOL><DEDENT>connection.set_tunnel(proxy_host, int(proxy_port), headers)<EOL><DEDENT>return connection<EOL>
Create connection for the request.