|
|
@@ -83,10 +83,6 @@ class Http
|
|
|
*/
|
|
|
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 @@ class Http
|
|
|
}
|
|
|
|
|
|
$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 @@ class Http
|
|
|
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;
|
|
|
}
|
|
|
|