|
9 | 9 | use Laravel\Octane\Contracts\ServesStaticFiles; |
10 | 10 | use Laravel\Octane\MimeType; |
11 | 11 | use Laravel\Octane\Octane; |
| 12 | +use Laravel\Octane\OctaneResponse; |
12 | 13 | use Laravel\Octane\RequestContext; |
13 | 14 | use Swoole\Http\Response as SwooleResponse; |
14 | 15 | use Symfony\Component\HttpFoundation\BinaryFileResponse; |
@@ -98,13 +99,13 @@ public function serveStaticFile(Request $request, RequestContext $context): void |
98 | 99 | * Send the response to the server. |
99 | 100 | * |
100 | 101 | * @param \Laravel\Octane\RequestContext $context |
101 | | - * @param \Symfony\Component\HttpFoundation\Response $response |
| 102 | + * @param \Laravel\Octane\OctaneResponse $octaneResponse |
102 | 103 | * @return void |
103 | 104 | */ |
104 | | - public function respond(RequestContext $context, Response $response): void |
| 105 | + public function respond(RequestContext $context, OctaneResponse $octaneResponse): void |
105 | 106 | { |
106 | | - $this->sendResponseHeaders($response, $context->swooleResponse); |
107 | | - $this->sendResponseContent($response, $context->swooleResponse); |
| 107 | + $this->sendResponseHeaders($octaneResponse->response, $context->swooleResponse); |
| 108 | + $this->sendResponseContent($octaneResponse, $context->swooleResponse); |
108 | 109 | } |
109 | 110 |
|
110 | 111 | /** |
@@ -150,23 +151,41 @@ public function sendResponseHeaders(Response $response, SwooleResponse $swooleRe |
150 | 151 | /** |
151 | 152 | * Send the headers from the Illuminate response to the Swoole response. |
152 | 153 | * |
153 | | - * @param \Symfony\Component\HtpFoundation\Response $response |
| 154 | + * @param \Laravel\Octane\OctaneResponse $response |
154 | 155 | * @param \Swoole\Http\Response $response |
155 | 156 | * @return void |
156 | 157 | */ |
157 | | - protected function sendResponseContent(Response $response, SwooleResponse $swooleResponse): void |
| 158 | + protected function sendResponseContent(OctaneResponse $octaneResponse, SwooleResponse $swooleResponse): void |
158 | 159 | { |
159 | | - if ($response instanceof StreamedResponse && property_exists($response, 'output')) { |
160 | | - $swooleResponse->end($response->output); |
| 160 | + if ($octaneResponse->response instanceof BinaryFileResponse) { |
| 161 | + $swooleResponse->sendfile($octaneResponse->response->getFile()->getPathname()); |
161 | 162 |
|
162 | 163 | return; |
163 | | - } elseif ($response instanceof BinaryFileResponse) { |
164 | | - $swooleResponse->sendfile($response->getFile()->getPathname()); |
| 164 | + } |
| 165 | + |
| 166 | + if ($octaneResponse->outputBuffer) { |
| 167 | + $swooleResponse->write($octaneResponse->outputBuffer); |
| 168 | + } |
| 169 | + |
| 170 | + if ($octaneResponse->response instanceof StreamedResponse) { |
| 171 | + ob_start(function ($data) use ($swooleResponse) { |
| 172 | + if (strlen($data) > 0) { |
| 173 | + $swooleResponse->write($data); |
| 174 | + } |
| 175 | + |
| 176 | + return ''; |
| 177 | + }, 1); |
| 178 | + |
| 179 | + $octaneResponse->response->sendContent(); |
| 180 | + |
| 181 | + ob_end_clean(); |
| 182 | + |
| 183 | + $swooleResponse->end(); |
165 | 184 |
|
166 | 185 | return; |
167 | 186 | } |
168 | 187 |
|
169 | | - $content = $response->getContent(); |
| 188 | + $content = $octaneResponse->response->getContent(); |
170 | 189 |
|
171 | 190 | $length = strlen($content); |
172 | 191 |
|
|
0 commit comments