Parse a single line. CRLF is stripped from the return value. Args: read_line: Generator-based coroutine that reads a LF-terminated line or raises an exception if there isn't enough data. Raises: EOFError: If the connection is closed without a CRLF.
(
read_line: Callable[[int], Generator[None, None, bytes | bytearray]],
)
| 300 | |
| 301 | |
| 302 | def parse_line( |
| 303 | read_line: Callable[[int], Generator[None, None, bytes | bytearray]], |
| 304 | ) -> Generator[None, None, bytes | bytearray]: |
| 305 | """ |
| 306 | Parse a single line. |
| 307 | |
| 308 | CRLF is stripped from the return value. |
| 309 | |
| 310 | Args: |
| 311 | read_line: Generator-based coroutine that reads a LF-terminated line |
| 312 | or raises an exception if there isn't enough data. |
| 313 | |
| 314 | Raises: |
| 315 | EOFError: If the connection is closed without a CRLF. |
| 316 | SecurityError: If the response exceeds a security limit. |
| 317 | |
| 318 | """ |
| 319 | try: |
| 320 | line = yield from read_line(MAX_LINE_LENGTH) |
| 321 | except RuntimeError: |
| 322 | raise SecurityError("line too long") |
| 323 | # Not mandatory but safe - https://datatracker.ietf.org/doc/html/rfc7230#section-3.5 |
| 324 | if not line.endswith(b"\r\n"): |
| 325 | raise EOFError("line without CRLF") |
| 326 | return line[:-2] |
| 327 | |
| 328 | |
| 329 | def parse_headers( |
no test coverage detected
searching dependent graphs…