MCPcopy
hub / github.com/tornadoweb/tornado / get

Method get

tornado/websocket.py:230–280  ·  view source on GitHub ↗
(self, *args: Any, **kwargs: Any)

Source from the content-addressed store, hash-verified

228 self._on_close_called = False
229
230 async def get(self, *args: Any, **kwargs: Any) -> None:
231 self.open_args = args
232 self.open_kwargs = kwargs
233
234 # Upgrade header should be present and should be equal to WebSocket
235 if self.request.headers.get("Upgrade", "").lower() != "websocket":
236 self.set_status(400)
237 log_msg = 'Can "Upgrade" only to "WebSocket".'
238 self.finish(log_msg)
239 gen_log.debug(log_msg)
240 return
241
242 # Connection header should be upgrade.
243 # Some proxy servers/load balancers
244 # might mess with it.
245 headers = self.request.headers
246 connection = map(
247 lambda s: s.strip().lower(), headers.get("Connection", "").split(",")
248 )
249 if "upgrade" not in connection:
250 self.set_status(400)
251 log_msg = '"Connection" must be "Upgrade".'
252 self.finish(log_msg)
253 gen_log.debug(log_msg)
254 return
255
256 # Handle WebSocket Origin naming convention differences
257 # The difference between version 8 and 13 is that in 8 the
258 # client sends a "Sec-Websocket-Origin" header and in 13 it's
259 # simply "Origin".
260 if "Origin" in self.request.headers:
261 origin = self.request.headers.get("Origin")
262 else:
263 origin = self.request.headers.get("Sec-Websocket-Origin", None)
264
265 # If there was an origin header, check to make sure it matches
266 # according to check_origin. When the origin is None, we assume it
267 # did not come from a browser and that it can be passed on.
268 if origin is not None and not self.check_origin(origin):
269 self.set_status(403)
270 log_msg = "Cross origin websockets not allowed"
271 self.finish(log_msg)
272 gen_log.debug(log_msg)
273 return
274
275 self.ws_connection = self.get_websocket_protocol()
276 if self.ws_connection:
277 await self.ws_connection.accept_connection(self)
278 else:
279 self.set_status(426, "Upgrade Required")
280 self.set_header("Sec-WebSocket-Version", "7, 8, 13")
281
282 @property
283 def ping_interval(self) -> Optional[float]:

Callers 12

ping_intervalMethod · 0.45
ping_timeoutMethod · 0.45
max_message_sizeMethod · 0.45
check_originMethod · 0.45
_challenge_responseMethod · 0.45
_accept_connectionMethod · 0.45
read_messageMethod · 0.45

Calls 7

check_originMethod · 0.95
set_statusMethod · 0.80
splitMethod · 0.80
set_headerMethod · 0.80
finishMethod · 0.45
accept_connectionMethod · 0.45

Tested by

no test coverage detected