Skip to content

Commit b2e9950

Browse files
committed
Code optimization
1 parent 9d84f4d commit b2e9950

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/Protocols/Http.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,12 @@ public static function input(string $buffer, TcpConnection $connection): int
9898
}
9999

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

105109
if ($length > $connection->maxPackageSize) {

0 commit comments

Comments
 (0)