10
10
11
11
class Response
12
12
{
13
+ const CHUNK_SIZE = 8192 ;
14
+
13
15
/**
14
16
* @var \Swoole\Http\Response
15
17
*/
@@ -46,7 +48,7 @@ public function __construct($illuminateResponse, SwooleResponse $swooleResponse)
46
48
}
47
49
48
50
/**
49
- * Sends HTTP headers and content.
51
+ * Send HTTP headers and content.
50
52
*
51
53
* @throws \InvalidArgumentException
52
54
*/
@@ -57,7 +59,7 @@ public function send()
57
59
}
58
60
59
61
/**
60
- * Sends HTTP headers.
62
+ * Send HTTP headers.
61
63
*
62
64
* @throws \InvalidArgumentException
63
65
*/
@@ -86,9 +88,11 @@ protected function sendHeaders()
86
88
$ this ->swooleResponse ->status ($ illuminateResponse ->getStatusCode ());
87
89
88
90
// cookies
91
+ // $cookie->isRaw() is supported after symfony/http-foundation 3.1
92
+ // and Laravel 5.3, so we can add it back now
89
93
foreach ($ illuminateResponse ->headers ->getCookies () as $ cookie ) {
90
- // may need to consider rawcookie
91
- $ this ->swooleResponse ->cookie (
94
+ $ method = $ cookie -> isRaw () ? ' rawcookie ' : ' cookie ' ;
95
+ $ this ->swooleResponse ->$ method (
92
96
$ cookie ->getName (),
93
97
$ cookie ->getValue (),
94
98
$ cookie ->getExpiresTime (),
@@ -101,7 +105,7 @@ protected function sendHeaders()
101
105
}
102
106
103
107
/**
104
- * Sends HTTP content.
108
+ * Send HTTP content.
105
109
*/
106
110
protected function sendContent ()
107
111
{
@@ -124,10 +128,13 @@ protected function sendContent()
124
128
*/
125
129
protected function sendInChunk ($ content )
126
130
{
127
- if ($ content ) {
128
- foreach (str_split ($ content , 1024 ) as $ v ) {
129
- $ this ->swooleResponse ->write ($ v );
130
- }
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 );
131
138
}
132
139
133
140
$ this ->swooleResponse ->end ();
0 commit comments