/**
* 发送响应
* @param $request Swoole\Request
* @param $response Swoole\Response
* @return bool
*/
function response(Swoole\Request $request, Swoole\Response $response)
{
if (!isset($response->head['Date'])) {
$response->head['Date'] = gmdate("D, d M Y H:i:s T");
}
if (!isset($response->head['Connection'])) {
//keepalive
if ($this->keepalive and (isset($request->head['Connection']) and strtolower($request->head['Connection']) == 'keep-alive')) {
$response->head['KeepAlive'] = 'on';
$response->head['Connection'] = 'keep-alive';
} else {
$response->head['KeepAlive'] = 'off';
$response->head['Connection'] = 'close';
}
}
//过期命中
if ($this->expire and $response->http_status == 304) {
$out = $response->getHeader();
return $this->server->send($request->fd, $out);
}
//压缩
if ($this->gzip) {
$response->head['Content-Encoding'] = 'deflate';
$response->body = gzdeflate($response->body, $this->config['server']['gzip_level']);
}
$out = $response->getHeader() . $response->body;
$ret = $this->server->send($request->fd, $out);
$this->afterResponse($request, $response);
return $ret;
}