@@ -28,40 +28,38 @@ def abort_connection(self):
2828 self .ws_connection ._abort ()
2929
3030 def _execute (self , transforms , * args , ** kwargs ):
31+ self ._transforms = transforms
3132 # Websocket only supports GET method
3233 if self .request .method != "GET" :
33- self .stream . write ( escape . utf8 (
34- "HTTP/1.1 405 Method Not Allowed \r \n "
34+ self .set_status ( 405 )
35+ self . finish ( escape . utf8 (
3536 "Allow: GET\r \n "
3637 "Connection: Close\r \n "
3738 "\r \n "
3839 ))
39- self .stream .close ()
4040 return
4141
4242 # Upgrade header should be present and should be equal to WebSocket
4343 if self .request .headers .get ("Upgrade" , "" ).lower () != "websocket" :
44- self .stream . write ( escape . utf8 (
45- "HTTP/1.1 400 Bad Request \r \n "
44+ self .set_status ( 400 )
45+ self . finish ( escape . utf8 (
4646 "Connection: Close\r \n "
4747 "\r \n "
4848 "Can \" Upgrade\" only to \" WebSocket\" ."
4949 ))
50- self .stream .close ()
5150 return
5251
5352 # Connection header should be upgrade. Some proxy servers/load balancers
5453 # might mess with it.
5554 headers = self .request .headers
5655 connection = map (lambda s : s .strip ().lower (), headers .get ("Connection" , "" ).split ("," ))
5756 if "upgrade" not in connection :
58- self .stream . write ( escape . utf8 (
59- "HTTP/1.1 400 Bad Request \r \n "
57+ self .set_status ( 400 )
58+ self . finish ( escape . utf8 (
6059 "Connection: Close\r \n "
6160 "\r \n "
6261 "\" Connection\" must be \" Upgrade\" ."
6362 ))
64- self .stream .close ()
6563 return
6664
6765 return super (SockJSWebSocketHandler , self )._execute (transforms , * args , ** kwargs )
0 commit comments