Skip to content
This repository has been archived by the owner on Sep 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #233 from swooletw/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
albertcht authored Mar 5, 2019
2 parents 9184fea + 0a39cad commit c266951
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
11 changes: 6 additions & 5 deletions src/Server/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
25 changes: 16 additions & 9 deletions src/Transformers/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

class Response
{
const CHUNK_SIZE = 8192;

/**
* @var \Swoole\Http\Response
*/
Expand Down Expand Up @@ -46,7 +48,7 @@ public function __construct($illuminateResponse, SwooleResponse $swooleResponse)
}

/**
* Sends HTTP headers and content.
* Send HTTP headers and content.
*
* @throws \InvalidArgumentException
*/
Expand All @@ -57,7 +59,7 @@ public function send()
}

/**
* Sends HTTP headers.
* Send HTTP headers.
*
* @throws \InvalidArgumentException
*/
Expand Down Expand Up @@ -86,9 +88,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(),
Expand All @@ -101,7 +105,7 @@ protected function sendHeaders()
}

/**
* Sends HTTP content.
* Send HTTP content.
*/
protected function sendContent()
{
Expand All @@ -124,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();
Expand Down

0 comments on commit c266951

Please sign in to comment.