예제 #1
0
    def read_headers(self, reader, lines):
        """read headers

        Args:
            reader (DataReader): type of reader that is required
            lines  (list): list of lines that we think is part of the header section
        Returns:
            `dict` of parsed_header
        """
        header_dict = defaultdict(str)
        while True:
            line = reader.read_line()
            if line is None:
                break
            line = line.strip()
            if not line:
                break
            lines.append(line)

            key, value = utils.parse_http_header(line)
            if key is None:
                # incorrect headers.
                continue

            header_dict[key.lower()] = value
        return header_dict
예제 #2
0
    def read_headers(self, reader, lines):
        """
        :type reader: DataReader
        :type lines: list
        :return: dict
        """
        header_dict = defaultdict(str)
        while True:
            line = reader.readline()
            if line is None:
                break
            line = line.strip()
            if not line:
                break
            lines.append(line)

            key, value = utils.parse_http_header(line)
            if key is None:
                # incorrect headers.
                continue

            header_dict[key.lower()] = value
        return header_dict
예제 #3
0
    def read_headers(self, reader, lines):
        """
        :type reader: DataReader
        :type lines: list
        :return: dict
        """
        header_dict = defaultdict(str)
        while True:
            line = reader.readline()
            if line is None:
                break
            line = line.strip()
            if not line:
                break
            lines.append(line)

            key, value = utils.parse_http_header(line)
            if key is None:
                # incorrect headers.
                continue

            header_dict[key.lower()] = value
        return header_dict
예제 #4
0
    def headers_handle(self, msg):
        while True:
            line = msg.readline()
            if None == line:
                return

            if '\r\n' == line:
                self.handle = self.body_handle
                break

            self.raw_headers.append(line)

            key, value = utils.parse_http_header(line)
            self.headers[key] = value
            if key == None:
                continue

            if key == 'content-length':
                self._len = int(value)

            elif key == 'transfer-encoding':
                if value.find("chunked") > -1:
                    self._chunked = True