WebSocket handshake request. Attributes: path: Request path, including optional query. headers: Request headers.
| 77 | |
| 78 | @dataclasses.dataclass |
| 79 | class Request: |
| 80 | """ |
| 81 | WebSocket handshake request. |
| 82 | |
| 83 | Attributes: |
| 84 | path: Request path, including optional query. |
| 85 | headers: Request headers. |
| 86 | """ |
| 87 | |
| 88 | path: str |
| 89 | headers: Headers |
| 90 | # body isn't useful is the context of this library. |
| 91 | |
| 92 | _exception: Exception | None = None |
| 93 | |
| 94 | @property |
| 95 | def exception(self) -> Exception | None: # pragma: no cover |
| 96 | warnings.warn( # deprecated in 10.3 - 2022-04-17 |
| 97 | "Request.exception is deprecated; use ServerProtocol.handshake_exc instead", |
| 98 | DeprecationWarning, |
| 99 | ) |
| 100 | return self._exception |
| 101 | |
| 102 | @classmethod |
| 103 | def parse( |
| 104 | cls, |
| 105 | read_line: Callable[[int], Generator[None, None, bytes | bytearray]], |
| 106 | ) -> Generator[None, None, Request]: |
| 107 | """ |
| 108 | Parse a WebSocket handshake request. |
| 109 | |
| 110 | This is a generator-based coroutine. |
| 111 | |
| 112 | The request path isn't URL-decoded or validated in any way. |
| 113 | |
| 114 | The request path and headers are expected to contain only ASCII |
| 115 | characters. Other characters are represented with surrogate escapes. |
| 116 | |
| 117 | :meth:`parse` doesn't attempt to read the request body because |
| 118 | WebSocket handshake requests don't have one. If the request contains a |
| 119 | body, it may be read from the data stream after :meth:`parse` returns. |
| 120 | |
| 121 | Args: |
| 122 | read_line: Generator-based coroutine that reads a LF-terminated |
| 123 | line or raises an exception if there isn't enough data |
| 124 | |
| 125 | Raises: |
| 126 | EOFError: If the connection is closed without a full HTTP request. |
| 127 | SecurityError: If the request exceeds a security limit. |
| 128 | ValueError: If the request isn't well formatted. |
| 129 | |
| 130 | """ |
| 131 | # https://datatracker.ietf.org/doc/html/rfc7230#section-3.1.1 |
| 132 | |
| 133 | # Parsing is simple because fixed values are expected for method and |
| 134 | # version and because path isn't checked. Since WebSocket software tends |
| 135 | # to implement HTTP/1.1 strictly, there's little need for lenient parsing. |
| 136 |
no outgoing calls
searching dependent graphs…