From 705a9809e2e352513315748b5aa398a0035fd884 Mon Sep 17 00:00:00 2001 From: Albert Chen Date: Sun, 3 Mar 2019 23:07:36 +0800 Subject: [PATCH 1/4] add raw cookie support back to response --- src/Transformers/Response.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Transformers/Response.php b/src/Transformers/Response.php index 6c7e053a..2fd6e306 100644 --- a/src/Transformers/Response.php +++ b/src/Transformers/Response.php @@ -86,9 +86,11 @@ protected function sendHeaders() $this->swooleResponse->status($illuminateResponse->getStatusCode()); // cookies + // $cookie->isRaw() is supported after symfony/http-foundation 3.1 + // and Laravel 5.3, so we can add it back now foreach ($illuminateResponse->headers->getCookies() as $cookie) { - // may need to consider rawcookie - $this->swooleResponse->cookie( + $method = $cookie->isRaw() ? 'rawcookie' : 'cookie'; + $this->swooleResponse->$method( $cookie->getName(), $cookie->getValue(), $cookie->getExpiresTime(), From b341335e098a3a3335554086357a63f9ce569739 Mon Sep 17 00:00:00 2001 From: Albert Chen Date: Sun, 3 Mar 2019 23:58:23 +0800 Subject: [PATCH 2/4] check strlen for response content --- src/Transformers/Response.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Transformers/Response.php b/src/Transformers/Response.php index 2fd6e306..f51ce3b2 100644 --- a/src/Transformers/Response.php +++ b/src/Transformers/Response.php @@ -10,6 +10,8 @@ class Response { + const CHUNK_SIZE = 1024; + /** * @var \Swoole\Http\Response */ @@ -46,7 +48,7 @@ public function __construct($illuminateResponse, SwooleResponse $swooleResponse) } /** - * Sends HTTP headers and content. + * Send HTTP headers and content. * * @throws \InvalidArgumentException */ @@ -57,7 +59,7 @@ public function send() } /** - * Sends HTTP headers. + * Send HTTP headers. * * @throws \InvalidArgumentException */ @@ -103,7 +105,7 @@ protected function sendHeaders() } /** - * Sends HTTP content. + * Send HTTP content. */ protected function sendContent() { @@ -126,10 +128,13 @@ protected function sendContent() */ protected function sendInChunk($content) { - if ($content) { - foreach (str_split($content, 1024) as $v) { - $this->swooleResponse->write($v); - } + if (strlen($content) <= static::CHUNK_SIZE) { + $this->swooleResponse->end($content); + return; + } + + foreach (str_split($content, static::CHUNK_SIZE) as $chunk) { + $this->swooleResponse->write($chunk); } $this->swooleResponse->end(); From 5d1a7d067070842228f1462376c5e69d55fdb925 Mon Sep 17 00:00:00 2001 From: Albert Chen Date: Tue, 5 Mar 2019 21:39:17 +0800 Subject: [PATCH 3/4] revert task_enable_coroutine support --- src/Server/Manager.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Server/Manager.php b/src/Server/Manager.php index b93e66c9..4258a707 100644 --- a/src/Server/Manager.php +++ b/src/Server/Manager.php @@ -5,6 +5,7 @@ use Exception; use Throwable; use Swoole\Process; +use Swoole\Server\Task; use Illuminate\Support\Str; use SwooleTW\Http\Helpers\OS; use SwooleTW\Http\Server\Sandbox; @@ -256,13 +257,13 @@ protected function resetOnRequest() * Set onTask listener. * * @param mixed $server - * @param string|\Swoole\Server\Task $taskIdOrTask - * @param string $srcWorkerId Optional - * @param mixed $data Optional + * @param string|\Swoole\Server\Task $taskId or $task + * @param string $srcWorkerId + * @param mixed $data */ - public function onTask($server, ...$args) + public function onTask($server, $taskId, $srcWorkerId, $data) { - $this->container->make('events')->dispatch('swoole.task', [$server, $args]); + $this->container->make('events')->dispatch('swoole.task', func_get_args()); try { // push websocket message From 0a39cad2db1f049524d3a6487328aa8acb6d664f Mon Sep 17 00:00:00 2001 From: Albert Chen Date: Tue, 5 Mar 2019 22:23:58 +0800 Subject: [PATCH 4/4] adjust chunk size for response to 8k --- src/Transformers/Response.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Transformers/Response.php b/src/Transformers/Response.php index f51ce3b2..416a26fa 100644 --- a/src/Transformers/Response.php +++ b/src/Transformers/Response.php @@ -10,7 +10,7 @@ class Response { - const CHUNK_SIZE = 1024; + const CHUNK_SIZE = 8192; /** * @var \Swoole\Http\Response