Skip to content
This repository was archived by the owner on Mar 24, 2025. It is now read-only.

Commit b341335

Browse files
committed
check strlen for response content
1 parent 705a980 commit b341335

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/Transformers/Response.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
class Response
1212
{
13+
const CHUNK_SIZE = 1024;
14+
1315
/**
1416
* @var \Swoole\Http\Response
1517
*/
@@ -46,7 +48,7 @@ public function __construct($illuminateResponse, SwooleResponse $swooleResponse)
4648
}
4749

4850
/**
49-
* Sends HTTP headers and content.
51+
* Send HTTP headers and content.
5052
*
5153
* @throws \InvalidArgumentException
5254
*/
@@ -57,7 +59,7 @@ public function send()
5759
}
5860

5961
/**
60-
* Sends HTTP headers.
62+
* Send HTTP headers.
6163
*
6264
* @throws \InvalidArgumentException
6365
*/
@@ -103,7 +105,7 @@ protected function sendHeaders()
103105
}
104106

105107
/**
106-
* Sends HTTP content.
108+
* Send HTTP content.
107109
*/
108110
protected function sendContent()
109111
{
@@ -126,10 +128,13 @@ protected function sendContent()
126128
*/
127129
protected function sendInChunk($content)
128130
{
129-
if ($content) {
130-
foreach (str_split($content, 1024) as $v) {
131-
$this->swooleResponse->write($v);
132-
}
131+
if (strlen($content) <= static::CHUNK_SIZE) {
132+
$this->swooleResponse->end($content);
133+
return;
134+
}
135+
136+
foreach (str_split($content, static::CHUNK_SIZE) as $chunk) {
137+
$this->swooleResponse->write($chunk);
133138
}
134139

135140
$this->swooleResponse->end();

0 commit comments

Comments
 (0)