Skip to content

Commit 8f1af04

Browse files
committed
less permissive
1 parent 623b8fe commit 8f1af04

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

httptools/parser/parser.pyi

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,36 @@ from array import array
33
from .protocol import HTTPProtocol
44

55
class HttpParser:
6-
def __init__(self, protocol: HTTPProtocol) -> None:
6+
def __init__(self, protocol: HTTPProtocol | object) -> None:
77
"""The HTTP parser.
88
99
Args:
10-
protocol(HTTPProtocol): a Python object with the following methods (all optional):
11-
- on_message_begin(self): ...
12-
- on_url(self, url: bytes): ...
13-
- on_header(self, name: bytes, value: bytes): ...
14-
- on_headers_complete(self): ...
15-
- on_body(self, body: bytes): ...
16-
- on_message_complete(self): ...
17-
- on_chunk_header(self): ...
18-
- on_chunk_complete(self): ...
19-
- on_status(self, status: bytes): ...
10+
protocol (HTTPProtocol): Callback interface for the parser.
2011
"""
2112

13+
def set_dangerous_leniencies(
14+
self,
15+
lenient_headers: bool | None = None,
16+
lenient_chunked_length: bool | None = None,
17+
lenient_keep_alive: bool | None = None,
18+
lenient_transfer_encoding: bool | None = None,
19+
lenient_version: bool | None = None,
20+
lenient_data_after_close: bool | None = None,
21+
lenient_optional_lf_after_cr: bool | None = None,
22+
lenient_optional_cr_before_lf: bool | None = None,
23+
lenient_optional_crlf_after_chunk: bool | None = None,
24+
lenient_spaces_after_chunk_size: bool | None = None,
25+
) -> None:
26+
"""Set dangerous leniencies for the parser."""
27+
2228
def get_http_version(self) -> str:
23-
"""Return an HTTP protocol version."""
29+
"""Retrieve the HTTP protocol version e.g. "1.1"."""
2430

2531
def should_keep_alive(self) -> bool:
26-
"""Return ``True`` if keep-alive mode is preferred."""
32+
"""Return `True` if keep-alive mode is preferred."""
2733

2834
def should_upgrade(self) -> bool:
29-
"""Return ``True`` if the parsed request is a valid Upgrade request.
35+
"""Return `True` if the parsed request is a valid Upgrade request.
3036
The method exposes a flag set just before on_headers_complete.
3137
Calling this method earlier will only yield `False`."""
3238

0 commit comments

Comments
 (0)