From 1a5f4ad3d6c5dcba22364b09af104526e10529ff Mon Sep 17 00:00:00 2001 From: walkor Date: Tue, 29 Oct 2024 16:47:27 +0800 Subject: [PATCH] Optimizations --- src/Protocols/Http.php | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/src/Protocols/Http.php b/src/Protocols/Http.php index 02cafdee6..228975cbb 100644 --- a/src/Protocols/Http.php +++ b/src/Protocols/Http.php @@ -83,10 +83,6 @@ public static function requestClass(?string $className = null): string */ public static function input(string $buffer, TcpConnection $connection): int { - static $input = []; - if (isset($input[$buffer])) { - return $input[$buffer]; - } $crlfPos = strpos($buffer, "\r\n\r\n"); if (false === $crlfPos) { // Judge whether the package length exceeds the limit. @@ -97,20 +93,13 @@ public static function input(string $buffer, TcpConnection $connection): int } $length = $crlfPos + 4; - $firstLine = explode(" ", strstr($buffer, "\r\n", true), 3); - - if (!in_array($firstLine[0], ['GET', 'POST', 'OPTIONS', 'HEAD', 'DELETE', 'PUT', 'PATCH'])) { + $method = strstr($buffer, ' ', true); + if (!in_array($method, ['GET', 'POST', 'OPTIONS', 'HEAD', 'DELETE', 'PUT', 'PATCH'])) { $connection->close("HTTP/1.1 400 Bad Request\r\nContent-Length: 0\r\n\r\n", true); return 0; } $header = substr($buffer, 0, $crlfPos); - - if (!str_contains($header, "\r\nHost: ") && $firstLine[2] === "HTTP/1.1") { - $connection->close("HTTP/1.1 400 Bad Request\r\nContent-Length: 0\r\n\r\n", true); - return 0; - } - if ($pos = stripos($header, "\r\nContent-Length: ")) { $length += (int)substr($header, $pos + 18, 10); $hasContentLength = true; @@ -130,13 +119,6 @@ public static function input(string $buffer, TcpConnection $connection): int return 0; } - if (!isset($buffer[TcpConnection::MAX_CACHE_STRING_LENGTH])) { - $input[$buffer] = $length; - if (count($input) > TcpConnection::MAX_CACHE_SIZE) { - unset($input[key($input)]); - } - } - return $length; }