@@ -25,6 +25,8 @@ class Builder implements Responsable
25
25
26
26
protected int $ bytesSent = 0 ;
27
27
28
+ protected bool $ sendHeaders = true ;
29
+
28
30
protected Collection $ meta ;
29
31
30
32
protected Queue $ queue ;
@@ -137,6 +139,8 @@ public function saveTo($output): int
137
139
default => throw new InvalidArgumentException ('Invalid output provided ' ),
138
140
};
139
141
142
+ $ this ->sendHeaders = false ;
143
+
140
144
return $ this ->process ();
141
145
}
142
146
@@ -151,8 +155,8 @@ public function process(): int
151
155
152
156
if ($ this ->canPredictZipSize ()) {
153
157
$ size = $ zip ->finish ();
154
- header ('Content-Length: ' .$ size );
155
- header ('X-Accel-Buffering: no ' );
158
+ $ this -> header ('Content-Length: ' .$ size );
159
+ $ this -> header ('X-Accel-Buffering: no ' );
156
160
157
161
event (new ZipStreaming ($ this , $ zip , $ size ));
158
162
@@ -214,6 +218,8 @@ public function getFinalSize(): int
214
218
215
219
public function response (): StreamedResponse
216
220
{
221
+ $ this ->sendHeaders = true ;
222
+
217
223
return new StreamedResponse (function () {
218
224
$ this ->process ();
219
225
}, 200 );
@@ -230,8 +236,9 @@ protected function prepare(): ZipStream
230
236
operationMode: $ this ->canPredictZipSize () ? OperationMode::SIMULATE_STRICT : OperationMode::NORMAL ,
231
237
comment: $ this ->getComment (),
232
238
outputStream: $ this ->getOutputStream (),
239
+ httpHeaderCallback: $ this ->header (...),
233
240
outputName: $ this ->getOutputName (),
234
- flushOutput: true ,
241
+ flushOutput: true
235
242
);
236
243
237
244
$ this ->queue ->each ->prepare ($ zip );
@@ -251,4 +258,13 @@ protected function getOutputStream(): StreamInterface
251
258
252
259
return $ this ->outputStream ;
253
260
}
261
+
262
+ protected function header (string $ header ): static
263
+ {
264
+ if ($ this ->sendHeaders ) {
265
+ header ($ header );
266
+ }
267
+
268
+ return $ this ;
269
+ }
254
270
}
0 commit comments