Skip to content

Commit

Permalink
Merge pull request #922 from joanhey/fix-400-bad-request
Browse files Browse the repository at this point in the history
Fix 400 Bad Request
  • Loading branch information
walkor authored Jun 28, 2023
2 parents 2a224cf + 59b6eb0 commit 4bde503
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Protocols/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,15 @@ public static function input(string $buffer, TcpConnection $connection): int
$firstLine = explode(" ", strstr($buffer, "\r\n", true), 3);

if (!in_array($firstLine[0], ['GET', 'POST', 'OPTIONS', 'HEAD', 'DELETE', 'PUT', 'PATCH'])) {
$connection->close("HTTP/1.1 400 Bad Request\r\n\r\n", true);
$connection->close("HTTP/1.1 400 Bad Request\r\nContent-Length: 0\r\n\r\n", true);
return 0;
}

$header = substr($buffer, 0, $crlfPos);
$hostHeaderPosition = stripos($header, "\r\nHost: ");

if (false === $hostHeaderPosition && $firstLine[2] === "HTTP/1.1") {
$connection->close("HTTP/1.1 400 Bad Request\r\n\r\n", true);
$connection->close("HTTP/1.1 400 Bad Request\r\nContent-Length: 0\r\n\r\n", true);
return 0;
}

Expand All @@ -139,7 +139,7 @@ public static function input(string $buffer, TcpConnection $connection): int
} else {
$hasContentLength = false;
if (false !== stripos($header, "\r\nTransfer-Encoding:")) {
$connection->close("HTTP/1.1 400 Bad Request\r\n\r\n", true);
$connection->close("HTTP/1.1 400 Bad Request\r\nContent-Length: 0\r\n\r\n", true);
return 0;
}
}
Expand Down

0 comments on commit 4bde503

Please sign in to comment.