Beispiel #1
0
    def _new_conn(self):
        """
        Return a fresh :class:`httplib.HTTPSConnection`.
        """
        self.num_connections += 1
        log.info("Starting new HTTPS connection (%d): %s"
                 % (self.num_connections, self.host))

        actual_host = self.host
        actual_port = self.port
        if self.proxy is not None:
            actual_host = self.proxy.host
            actual_port = self.proxy.port

        if not ssl:  # Platform-specific: Python compiled without +ssl
            if not HTTPSConnection or HTTPSConnection is object:
                raise SSLError("Can't connect to HTTPS URL because the SSL "
                               "module is not available.")

            connection = HTTPSConnection(host=actual_host,
                                         port=actual_port,
                                         strict=self.strict)

        else:
            connection = VerifiedHTTPSConnection(host=actual_host,
                                                 port=actual_port,
                                                 strict=self.strict)

            connection.set_cert(key_file=self.key_file, cert_file=self.cert_file,
                                cert_reqs=self.cert_reqs, ca_certs=self.ca_certs,
                                assert_hostname=self.assert_hostname,
                                assert_fingerprint=self.assert_fingerprint)

            connection.ssl_version = self.ssl_version

        if self.proxy is not None:
            # Python 2.7+
            try:
                set_tunnel = connection.set_tunnel
            except AttributeError:  # Platform-specific: Python 2.6
                set_tunnel = connection._set_tunnel
            set_tunnel(self.host, self.port, self.proxy_headers)
            # Establish tunnel connection early, because otherwise httplib
            # would improperly set Host: header to proxy's IP:port.
            connection.connect()

        return connection
Beispiel #2
0
    def _new_conn(self):
        """
        Return a fresh :class:`httplib.HTTPSConnection`.
        """
        self.num_connections += 1
        log.info("Starting new HTTPS connection (%d): %s"
                 % (self.num_connections, self.host))

        actual_host = self.host
        actual_port = self.port
        if self.proxy is not None:
            actual_host = self.proxy.host
            actual_port = self.proxy.port

        if not ssl: # Platform-specific: Python compiled without +ssl
            if not HTTPSConnection or HTTPSConnection is object:
                raise SSLError("Can't connect to HTTPS URL because the SSL "
                               "module is not available.")

            connection = HTTPSConnection(host=actual_host,
                                         port=actual_port,
                                         strict=self.strict)

        else:
            connection = VerifiedHTTPSConnection(host=actual_host,
                                                 port=actual_port,
                                                 strict=self.strict)

            connection.set_cert(key_file=self.key_file, cert_file=self.cert_file,
                                cert_reqs=self.cert_reqs, ca_certs=self.ca_certs)

            connection.ssl_version = self.ssl_version

        if self.proxy is not None:
            # Python 2.7+
            try:
                set_tunnel = connection.set_tunnel
            # Python 2.6
            except AttributeError:
                set_tunnel = connection._set_tunnel
            set_tunnel(self.host, self.port, self.proxy_headers)
            # Establish tunnel connection early, because otherwise httplib
            # would improperly set Host: header to proxy's IP:port.
            connection.connect()

        return connection