/**
* 静态请求
* @param $request
* @param $response
* @return unknown_type
*/
function processStatic($request, Swoole\Response $response)
{
$path = $this->document_root . '/' . $request->meta['path'];
if (is_file($path)) {
$read_file = true;
if ($this->expire) {
$expire = intval($this->config['server']['expire_time']);
$fstat = stat($path);
//过期控制信息
if (isset($request->head['If-Modified-Since'])) {
$lastModifiedSince = strtotime($request->head['If-Modified-Since']);
if ($lastModifiedSince and $fstat['mtime'] <= $lastModifiedSince) {
//不需要读文件了
$read_file = false;
$response->setHttpStatus(304);
}
} else {
$response->head['Cache-Control'] = "max-age={$expire}";
$response->head['Pragma'] = "max-age={$expire}";
$response->head['Last-Modified'] = date(self::DATE_FORMAT_HTTP, $fstat['mtime']);
$response->head['Expires'] = "max-age={$expire}";
}
}
$ext_name = Swoole\Upload::getFileExt($request->meta['path']);
if ($read_file) {
$response->head['Content-Type'] = $this->mime_types[$ext_name];
$response->body = file_get_contents($path);
}
return true;
} else {
return false;
}
}