Parcourir la source

Simplifying subprotocol parse.

Signed-off-by: tianhe1986 <w1s2j3229@163.com>
tianhe1986 il y a 7 ans
Parent
commit
499566845e
1 fichiers modifiés avec 4 ajouts et 8 suppressions
  1. 4 8
      Protocols/Ws.php

+ 4 - 8
Protocols/Ws.php

@@ -411,14 +411,10 @@ class Ws
 
             // handshake complete
 
-	    // Get WebSocket subprotocol (if specified by server)
-    	    $header = explode("\r\n", substr($buffer, 0, $pos));
-	    foreach ($header as $hrow) {
-		if (preg_match("#^(.+?)\:(.+?)$#", $hrow, $m) && ($m[1] == "Sec-WebSocket-Protocol")) {
-		    $connection->WSServerProtocol = trim($m[2]);
-		}
-
-	    }
+            // Get WebSocket subprotocol (if specified by server)
+            if (preg_match("/Sec-WebSocket-Protocol: *(.*?)\r\n/i", $buffer, $match)) {
+                $connection->WSServerProtocol = trim($match[1]);
+            }
 
             $connection->handshakeStep = 2;
             $handshake_response_length = $pos + 4;