Skip to content

Commit

Permalink
fix keep-alived only on php
Browse files Browse the repository at this point in the history
  • Loading branch information
linkec committed Jul 27, 2019
1 parent c894fd3 commit 078cf5f
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions WebServer.php
Expand Up @@ -154,7 +154,11 @@ public function onMessage($connection)
$workerman_url_info = parse_url('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
if (!$workerman_url_info) {
Http::header('HTTP/1.1 400 Bad Request');
$connection->close('<h1>400 Bad Request</h1>');
if (strtolower($_SERVER['HTTP_CONNECTION']) === "keep-alive") {
$connection->send('<h1>400 Bad Request</h1>');
} else {
$connection->close('<h1>400 Bad Request</h1>');
}
return;
}

Expand Down Expand Up @@ -188,7 +192,11 @@ public function onMessage($connection)
$workerman_root_dir_realpath)
) {
Http::header('HTTP/1.1 400 Bad Request');
$connection->close('<h1>400 Bad Request</h1>');
if (strtolower($_SERVER['HTTP_CONNECTION']) === "keep-alive") {
$connection->send('<h1>400 Bad Request</h1>');
} else {
$connection->close('<h1>400 Bad Request</h1>');
}
return;
}

Expand Down Expand Up @@ -233,7 +241,11 @@ public function onMessage($connection)
}else{
$html404 = '<html><head><title>404 File not found</title></head><body><center><h3>404 Not Found</h3></center></body></html>';
}
$connection->close($html404);
if (strtolower($_SERVER['HTTP_CONNECTION']) === "keep-alive") {
$connection->send($html404);
} else {
$connection->close($html404);
}
return;
}
}
Expand All @@ -249,7 +261,11 @@ public static function sendFile($connection, $file_path)
// 304
Http::header('HTTP/1.1 304 Not Modified');
// Send nothing but http headers..
$connection->close('');
if (strtolower($_SERVER['HTTP_CONNECTION']) === "keep-alive") {
$connection->send('');
} else {
$connection->close('');
}
return;
}
}
Expand Down

0 comments on commit 078cf5f

Please sign in to comment.