$http_worker->onMessage = static function ($connection, $request) {
// 靜態(tài)資源目錄
$staticDir = 'G:/sms/sms/laraval/resources';
// 請求的文件路徑
$filePath = $staticDir . $request['server']['REQUEST_URI'];
// 檢查文件是否存在
if(is_file($filePath)) {
// 直接返回文件內(nèi)容
// ======發(fā)送http頭======
$file_size = filesize($filePath);
$header = "HTTP/1.1 200 OK\r\n";
$header .= "Content-Type: ". mime_content_type($filePath) . "\n";
$header .= "Connection: keep-alive\r\n";
$header .= "Content-Length: $file_size\r\n\r\n";
$connection->send($header, true);
$fileContent = file_get_contents($filePath);
$connection->send($fileContent);
} else {
$connection->send(run());
}
};
這樣寫請求靜態(tài)資源header 沒有文件類型,客戶端打開的圖片是圖片內(nèi)容,應(yīng)該怎樣修改