def run(self):
        """Method to run when the thread is started."""

        if not self._validate_request():
            return

        # Determine the class to use for the connection.
        if self.request.protocol == "https":
            try:
                connection_class = HTTPSConnection
            except __HOLE__:
                message = "Your Python interpreter does not have SSL. " \
                          "If you have cURL installed, set the http_client " \
                          "setting to \"curl\"."
                sublime.error_message(message)
                self.message = "Unable to make HTTPS requests."
                self.success = False
                return

        else:
            connection_class = HTTPConnection

        # Create the connection.
        conn = connection_class(self.request.host,
                                port=self.request.port,
                                timeout=self._timeout)

        try:

            # Body: encode and add Content-length header
            body_bytes = None
            if self.request.body:
                body_bytes = self.request.body.encode(self._encoding)
                if not self.request.get_header("Content-length"):
                    self.request.headers.append(("Content-length", len(body_bytes)))

            # Insert a host header, if needed.
            if not self.request.get_header("host"):
               self.request.headers.append(("Host", self.request.host))

            # Method and Path
            conn.putrequest(self.request.method, self.request.full_path, True, True)

            # Headers
            for key, value in self.request.headers:
                conn.putheader(key, value)
            conn.endheaders()

            # Body
            if body_bytes:
                conn.send(body_bytes)

        except socket.gaierror:
            self.message = "Unable to make request. " \
                           "Make sure the hostname is valid."
            self.success = False
            conn.close()
            return

        except ConnectionRefusedError:
            self.message = "Connection refused."
            self.success = False
            conn.close()
            return

        # Read the response.
        #noinspection PyBroadException
        try:
            time_start = time.time()
            resp = conn.getresponse()
        except socket.timeout:
            self.message = "Request timed out."
            self.success = False
            conn.close()
            return
        except:
            self.message = "Unexpected error making request."
            self.success = False
            conn.close()
            return

        # Read the response
        self._read_response(resp)
        time_end = time.time()
        self.elapsed = time_end - time_start
        conn.close()
        self.success = True
dataset/ETHPy150Open pjdietz/rester-sublime-http-client/rester/http.py/HttpClientRequestThread.run