(self, method, url, skip_host=0)
Send a request to the server.

        `method' specifies an HTTP request method, e.g. 'GET'.
        `url' specifies the object being requested, e.g. '/index.html'.
Send a request to the server.
Send a request to the server .
def putrequest(self, method, url, skip_host=0):
        """Send a request to the server.

        `method' specifies an HTTP request method, e.g. 'GET'.
        `url' specifies the object being requested, e.g. '/index.html'.
        """

        # check if a prior response has been completed
        if self.__response and self.__response.isclosed():
            self.__response = None

        #
        # in certain cases, we cannot issue another request on this connection.
        # this occurs when:
        #   1) we are in the process of sending a request.   (_CS_REQ_STARTED)
        #   2) a response to a previous request has signalled that it is going
        #      to close the connection upon completion.
        #   3) the headers for the previous response have not been read, thus
        #      we cannot determine whether point (2) is true.   (_CS_REQ_SENT)
        #
        # if there is no prior response, then we can request at will.
        #
        # if point (2) is true, then we will have passed the socket to the
        # response (effectively meaning, "there is no prior response"), and
        # will open a new one when a new request is made.
        #
        # Note: if a prior response exists, then we *can* start a new request.
        #       We are not allowed to begin fetching the response to this new
        #       request, however, until that prior response is complete.
        #
        if self.__state == _CS_IDLE:
            self.__state = _CS_REQ_STARTED
        else:
            raise CannotSendRequest()

        if not url:
            url = '/'
        str = '%s %s %s\r\n' % (method, url, self._http_vsn_str)

        try:
            self.send(str)
        except socket.error, v:
            # trap 'Broken pipe' if we're allowed to automatically reconnect
            if v[0] != 32 or not self.auto_open:
                raise
            # try one more time (the socket was closed; this will reopen)
            self.send(str)

        if self._http_vsn == 11:
            # Issue some standard headers for better HTTP/1.1 compliance

            if not skip_host:
                # this header is issued *only* for HTTP/1.1
                # connections. more specifically, this means it is
                # only issued when the client uses the new
                # HTTPConnection() class. backwards-compat clients
                # will be using HTTP/1.0 and those clients may be
                # issuing this header themselves. we should NOT issue
                # it twice; some web servers (such as Apache) barf
                # when they see two Host: headers

                # If we need a non-standard port,include it in the
                # header.  If the request is going through a proxy,
                # but the host of the actual URL, not the host of the
                # proxy.

                netloc = ''
                if startswith(url, 'http'):
                    nil, netloc, nil, nil, nil = urlsplit(url)

                if netloc:
                    self.putheader('Host', netloc)
                elif self.port == HTTP_PORT:
                    self.putheader('Host', self.host)
                else:
                    self.putheader('Host', "%s:%s" % (self.host, self.port))

            # note: we are assuming that clients will not attempt to set these
            #       headers since *this* library must deal with the
            #       consequences. this also means that when the supporting
            #       libraries are updated to recognize other forms, then this
            #       code should be changed (removed or updated).

            # we only want a Content-Encoding of "identity" since we don't
            # support encodings such as x-gzip or x-deflate.
            self.putheader('Accept-Encoding', 'identity')

            # we can accept "chunked" Transfer-Encodings, but no others
            # NOTE: no TE header implies *only* "chunked"
            #self.putheader('TE', 'chunked')

            # if TE is supplied in the header, then it must appear in a
            # Connection header.
            #self.putheader('Connection', 'TE')

        else:
            # For HTTP/1.0, the server will assume "not chunked"
            pass
def putrequest ( self , method , url , skip_host = 0 ) : # check if a prior response has been completed if self . __response and self . __response . isclosed ( ) : self . __response = None # # in certain cases, we cannot issue another request on this connection. # this occurs when: #   1) we are in the process of sending a request.   (_CS_REQ_STARTED) #   2) a response to a previous request has signalled that it is going #      to close the connection upon completion. #   3) the headers for the previous response have not been read, thus #      we cannot determine whether point (2) is true.   (_CS_REQ_SENT) # # if there is no prior response, then we can request at will. # # if point (2) is true, then we will have passed the socket to the # response (effectively meaning, "there is no prior response"), and # will open a new one when a new request is made. # # Note: if a prior response exists, then we *can* start a new request. #       We are not allowed to begin fetching the response to this new #       request, however, until that prior response is complete. # if self . __state == _CS_IDLE : self . __state = _CS_REQ_STARTED else : raise CannotSendRequest ( ) if not url : url = '/' str = '%s %s %s\r\n' % ( method , url , self . _http_vsn_str ) try : self . send ( str ) except socket . error , v : # trap 'Broken pipe' if we're allowed to automatically reconnect if v [ 0 ] != 32 or not self . auto_open : raise # try one more time (the socket was closed; this will reopen) self . send ( str ) if self . _http_vsn == 11 : # Issue some standard headers for better HTTP/1.1 compliance if not skip_host : # this header is issued *only* for HTTP/1.1 # connections. more specifically, this means it is # only issued when the client uses the new # HTTPConnection() class. backwards-compat clients # will be using HTTP/1.0 and those clients may be # issuing this header themselves. we should NOT issue # it twice; some web servers (such as Apache) barf # when they see two Host: headers # If we need a non-standard port,include it in the # header.  If the request is going through a proxy, # but the host of the actual URL, not the host of the # proxy. netloc = '' if startswith ( url , 'http' ) : nil , netloc , nil , nil , nil = urlsplit ( url ) if netloc : self . putheader ( 'Host' , netloc ) elif self . port == HTTP_PORT : self . putheader ( 'Host' , self . host ) else : self . putheader ( 'Host' , "%s:%s" % ( self . host , self . port ) ) # note: we are assuming that clients will not attempt to set these #       headers since *this* library must deal with the #       consequences. this also means that when the supporting #       libraries are updated to recognize other forms, then this #       code should be changed (removed or updated). # we only want a Content-Encoding of "identity" since we don't # support encodings such as x-gzip or x-deflate. self . putheader ( 'Accept-Encoding' , 'identity' ) # we can accept "chunked" Transfer-Encodings, but no others # NOTE: no TE header implies *only* "chunked" #self.putheader('TE', 'chunked') # if TE is supplied in the header, then it must appear in a # Connection header. #self.putheader('Connection', 'TE') else : # For HTTP/1.0, the server will assume "not chunked" pass