MCPcopy Create free account
hub / github.com/python-websockets/websockets / Request

Class Request

src/websockets/http11.py:79–178  ·  view source on GitHub ↗

WebSocket handshake request. Attributes: path: Request path, including optional query. headers: Request headers.

Source from the content-addressed store, hash-verified

77
78@dataclasses.dataclass
79class 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

Callers 3

make_requestFunction · 0.90
connectMethod · 0.85
test_serializeMethod · 0.85

Calls

no outgoing calls

Tested by 2

make_requestFunction · 0.72
test_serializeMethod · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…