(self, request_method)
return length
Set initial length value for Response content if available.
Set initial length value for Response content if available.
Set initial length value for Response content if available .
def _init_length(self, request_method):
        """
        Set initial length value for Response content if available.
        """
        length = self.headers.get('content-length')

        if length is not None:
            if self.chunked:
                # This Response will fail with an IncompleteRead if it can't be
                # received as chunked. This method falls back to attempt reading
                # the response before raising an exception.
                log.warning("Received response with both Content-Length and "
                            "Transfer-Encoding set. This is expressly forbidden "
                            "by RFC 7230 sec 3.3.2. Ignoring Content-Length and "
                            "attempting to process response as Transfer-Encoding: "
                            "chunked.")
                return None

            try:
                # RFC 7230 section 3.3.2 specifies multiple content lengths can
                # be sent in a single Content-Length header
                # (e.g. Content-Length: 42, 42). This line ensures the values
                # are all valid ints and that as long as the `set` length is 1,
                # all values are the same. Otherwise, the header is invalid.
                lengths = set([int(val) for val in length.split(',')])
                if len(lengths) > 1:
                    raise InvalidHeader("Content-Length contained multiple "
                                        "unmatching values (%s)" % length)
                length = lengths.pop()
            except ValueError:
                length = None
            else:
                if length < 0:
                    length = None

        # Convert status to int for comparison
        # In some cases, httplib returns a status of "_UNKNOWN"
        try:
            status = int(self.status)
        except ValueError:
            status = 0

        # Check for responses that shouldn't include a body
        if status in (204, 304) or 100 <= status < 200 or request_method == 'HEAD':
            length = 0

        return length
def _init_length ( self , request_method ) : length = self . headers . get ( 'content-length' ) if length is not None : if self . chunked : # This Response will fail with an IncompleteRead if it can't be # received as chunked. This method falls back to attempt reading # the response before raising an exception. log . warning ( "Received response with both Content-Length and " "Transfer-Encoding set. This is expressly forbidden " "by RFC 7230 sec 3.3.2. Ignoring Content-Length and " "attempting to process response as Transfer-Encoding: " "chunked." ) return None try : # RFC 7230 section 3.3.2 specifies multiple content lengths can # be sent in a single Content-Length header # (e.g. Content-Length: 42, 42). This line ensures the values # are all valid ints and that as long as the `set` length is 1, # all values are the same. Otherwise, the header is invalid. lengths = set ( [ int ( val ) for val in length . split ( ',' ) ] ) if len ( lengths ) > 1 : raise InvalidHeader ( "Content-Length contained multiple " "unmatching values (%s)" % length ) length = lengths . pop ( ) except ValueError : length = None else : if length < 0 : length = None # Convert status to int for comparison # In some cases, httplib returns a status of "_UNKNOWN" try : status = int ( self . status ) except ValueError : status = 0 # Check for responses that shouldn't include a body if status in ( 204 , 304 ) or 100 <= status < 200 or request_method == 'HEAD' : length = 0 return length