modify
This commit is contained in:
@@ -161,7 +161,7 @@ class Response extends HttpService
|
|||||||
$this->response = $response;
|
$this->response = $response;
|
||||||
}
|
}
|
||||||
if ($this->response instanceof SResponse) {
|
if ($this->response instanceof SResponse) {
|
||||||
$this->sendData($sendData, $statusCode);
|
$this->sendData($this->response, $sendData, $statusCode);
|
||||||
} else {
|
} else {
|
||||||
if (!empty(request()->fd)) {
|
if (!empty(request()->fd)) {
|
||||||
return '';
|
return '';
|
||||||
@@ -221,37 +221,36 @@ class Response extends HttpService
|
|||||||
* @param $status
|
* @param $status
|
||||||
* @throws Exception
|
* @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;
|
return;
|
||||||
}
|
}
|
||||||
$this->setHeaders($status);
|
$this->setHeaders($response, $status);
|
||||||
if (empty($sendData)) {
|
if (empty($sendData)) {
|
||||||
$this->response->end('');
|
$response->end('');
|
||||||
} else {
|
} else {
|
||||||
$message = '[' . date('Y-m-d H:i:s') . ']' . $sendData . PHP_EOL . PHP_EOL;
|
$message = '[' . date('Y-m-d H:i:s') . ']' . $sendData . PHP_EOL . PHP_EOL;
|
||||||
Snowflake::writeFile(storage('response.log'), $message, FILE_APPEND);
|
Snowflake::writeFile(storage('response.log'), $message, FILE_APPEND);
|
||||||
$this->response->end($sendData);
|
$response->end($sendData);
|
||||||
}
|
}
|
||||||
$this->response = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $status
|
* @param $status
|
||||||
*/
|
*/
|
||||||
private function setHeaders($status): void
|
private function setHeaders($response, $status): void
|
||||||
{
|
{
|
||||||
$this->response->status($status);
|
$response->status($status);
|
||||||
$this->response->header('Content-Type', $this->getContentType());
|
$response->header('Content-Type', $this->getContentType());
|
||||||
$this->response->header('Run-Time', $this->getRuntime());
|
$response->header('Run-Time', $this->getRuntime());
|
||||||
|
|
||||||
if (empty($this->headers) || !is_array($this->headers)) {
|
if (empty($this->headers) || !is_array($this->headers)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
foreach ($this->headers as $key => $header) {
|
foreach ($this->headers as $key => $header) {
|
||||||
$this->response->header($key, $header, true);
|
$response->header($key, $header, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user