Skip to content

Commit

Permalink
Code optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
walkor committed Dec 28, 2024
1 parent 9d84f4d commit b2e9950
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Protocols/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,12 @@ public static function input(string $buffer, TcpConnection $connection): int
}

$header = substr($buffer, 0, $crlfPos);
if (preg_match("/\r\ncontent-length: ?(\d+)/i", $header, $match)) {
$length += (int)$match[1];
if (preg_match('/\b(?:Transfer-Encoding\b.*)|(?:Content-Length:\s*(\d+)(?!.*\bTransfer-Encoding\b))/is', $header, $matches)) {
if (!isset($matches[1])) {
$connection->close("HTTP/1.1 400 Bad Request\r\nContent-Length: 0\r\n\r\n", true);
return 0;
}
$length += (int)$matches[1];
}

if ($length > $connection->maxPackageSize) {
Expand Down

0 comments on commit b2e9950

Please sign in to comment.