MCPcopy Index your code
hub / github.com/python-websockets/websockets / process_response

Method process_response

src/websockets/client.py:131–174  ·  view source on GitHub ↗

Check a handshake response. Args: request: WebSocket handshake response received from the server. Raises: InvalidHandshake: If the handshake response is invalid.

(self, response: Response)

Source from the content-addressed store, hash-verified

129 return Request(self.uri.resource_name, headers)
130
131 def process_response(self, response: Response) -> None:
132 """
133 Check a handshake response.
134
135 Args:
136 request: WebSocket handshake response received from the server.
137
138 Raises:
139 InvalidHandshake: If the handshake response is invalid.
140
141 """
142
143 if response.status_code != 101:
144 raise InvalidStatus(response)
145
146 headers = response.headers
147
148 connection: list[ConnectionOption] = sum(
149 [parse_connection(value) for value in headers.get_all("Connection")], []
150 )
151 if not any(value.lower() == "upgrade" for value in connection):
152 raise InvalidUpgrade(
153 "Connection", ", ".join(connection) if connection else None
154 )
155
156 upgrade: list[UpgradeProtocol] = sum(
157 [parse_upgrade(value) for value in headers.get_all("Upgrade")], []
158 )
159 # For compatibility with non-strict implementations, ignore case when
160 # checking the Upgrade header. It's supposed to be 'WebSocket'.
161 if not (len(upgrade) == 1 and upgrade[0].lower() == "websocket"):
162 raise InvalidUpgrade("Upgrade", ", ".join(upgrade) if upgrade else None)
163
164 try:
165 s_w_accept = headers["Sec-WebSocket-Accept"]
166 except KeyError:
167 raise InvalidHeader("Sec-WebSocket-Accept") from None
168 except MultipleValuesError:
169 raise InvalidHeader("Sec-WebSocket-Accept", "multiple values") from None
170 if s_w_accept != accept_key(self.key):
171 raise InvalidHeaderValue("Sec-WebSocket-Accept", s_w_accept)
172
173 self.extensions = self.process_extensions(headers)
174 self.subprotocol = self.process_subprotocol(headers)
175
176 def process_extensions(self, headers: Headers) -> list[Extension]:
177 """

Callers 1

parseMethod · 0.95

Calls 10

process_extensionsMethod · 0.95
process_subprotocolMethod · 0.95
InvalidStatusClass · 0.85
parse_connectionFunction · 0.85
InvalidUpgradeClass · 0.85
parse_upgradeFunction · 0.85
InvalidHeaderClass · 0.85
accept_keyFunction · 0.85
InvalidHeaderValueClass · 0.85
get_allMethod · 0.80

Tested by

no test coverage detected