Updates the dictionary with a single header line. >>> h = HTTPHeaders() >>> h.parse_line("Content-Type: text/html") >>> h.get('content-type') 'text/html'
(self, line: str)
| 160 | yield (name, value) |
| 161 | |
| 162 | def parse_line(self, line: str) -> None: |
| 163 | """Updates the dictionary with a single header line. |
| 164 | |
| 165 | >>> h = HTTPHeaders() |
| 166 | >>> h.parse_line("Content-Type: text/html") |
| 167 | >>> h.get('content-type') |
| 168 | 'text/html' |
| 169 | """ |
| 170 | if line[0].isspace(): |
| 171 | # continuation of a multi-line header |
| 172 | if self._last_key is None: |
| 173 | raise HTTPInputError("first header line cannot start with whitespace") |
| 174 | new_part = " " + line.lstrip() |
| 175 | self._as_list[self._last_key][-1] += new_part |
| 176 | self._dict[self._last_key] += new_part |
| 177 | else: |
| 178 | try: |
| 179 | name, value = line.split(":", 1) |
| 180 | except ValueError: |
| 181 | raise HTTPInputError("no colon in header line") |
| 182 | self.add(name, value.strip()) |
| 183 | |
| 184 | @classmethod |
| 185 | def parse(cls, headers: str) -> "HTTPHeaders": |
no test coverage detected