This commit is contained in:
as2252258@163.com
2021-04-24 16:45:38 +08:00
parent dfa7ebf521
commit b6c0619a2e
+11 -12
View File
@@ -161,7 +161,7 @@ class Response extends HttpService
$this->response = $response;
}
if ($this->response instanceof SResponse) {
$this->sendData($sendData, $statusCode);
$this->sendData($this->response, $sendData, $statusCode);
} else {
if (!empty(request()->fd)) {
return '';
@@ -221,37 +221,36 @@ class Response extends HttpService
* @param $status
* @throws Exception
*/
private function sendData($sendData, $status): void
private function sendData($response, $sendData, $status): void
{
if (!$this->response->isWritable()) {
if (!swoole()->exist($response->fd) || !$response->isWritable()) {
return;
}
$this->setHeaders($status);
$this->setHeaders($response, $status);
if (empty($sendData)) {
$this->response->end('');
$response->end('');
} else {
$message = '[' . date('Y-m-d H:i:s') . ']' . $sendData . PHP_EOL . PHP_EOL;
Snowflake::writeFile(storage('response.log'), $message, FILE_APPEND);
$this->response->end($sendData);
$response->end($sendData);
}
$this->response = null;
}
/**
* @param $status
*/
private function setHeaders($status): void
private function setHeaders($response, $status): void
{
$this->response->status($status);
$this->response->header('Content-Type', $this->getContentType());
$this->response->header('Run-Time', $this->getRuntime());
$response->status($status);
$response->header('Content-Type', $this->getContentType());
$response->header('Run-Time', $this->getRuntime());
if (empty($this->headers) || !is_array($this->headers)) {
return;
}
foreach ($this->headers as $key => $header) {
$this->response->header($key, $header, true);
$response->header($key, $header, true);
}
}