MCPcopy Create free account
hub / github.com/AstroPrint/AstroBox / _execute

Method _execute

src/ext/sockjs/tornado/websocket.py:37–64  ·  view source on GitHub ↗
(self, transforms, *args, **kwargs)

Source from the content-addressed store, hash-verified

35
36 @gen.coroutine
37 def _execute(self, transforms, *args, **kwargs):
38 self._transforms = transforms
39 # Websocket only supports GET method
40 if self.request.method != "GET":
41 self.set_status(405)
42 self.set_header("Allow", "GET")
43 self.set_header("Connection", "Close")
44 self.finish("WebSocket only supports GET requests.")
45 return
46
47 # Upgrade header should be present and should be equal to WebSocket
48 if self.request.headers.get("Upgrade", "").lower() != "websocket":
49 self.set_status(400)
50 self.set_header("Connection", "Close")
51 self.finish("Can \"Upgrade\" only to \"WebSocket\".")
52 return
53
54 # Connection header should be upgrade. Some proxy servers/load balancers
55 # might mess with it.
56 headers = self.request.headers
57 connection = map(lambda s: s.strip().lower(), headers.get("Connection", "").split(","))
58 if "upgrade" not in connection:
59 self.set_status(400)
60 self.set_header("Connection", "Close")
61 self.finish("\"Connection\" must be \"Upgrade\".")
62 return
63
64 yield super(SockJSWebSocketHandler, self)._execute(transforms, *args, **kwargs)

Callers

nothing calls this directly

Calls 2

finishMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected