22
33namespace Laravel \Octane \Tests ;
44
5+ use Config ;
56use Exception ;
67use Illuminate \Http \Request ;
78use Illuminate \Http \Response ;
@@ -140,7 +141,7 @@ public function test_static_file_headers_can_be_sent(): void
140141 ]);
141142
142143 $ swooleResponse ->shouldReceive ('status ' )->once ()->with (200 );
143- $ swooleResponse ->shouldReceive ('header ' )->once ()->with ('X-Test-Header ' , 'Valid ' );
144+ $ swooleResponse ->shouldReceive ('header ' )->once ()->with ('X-Test-Header ' , 'Valid ' , true );
144145 $ swooleResponse ->shouldReceive ('header ' )->once ()->with ('Content-Type ' , 'text/plain ' );
145146 $ swooleResponse ->shouldReceive ('sendfile ' )->once ()->with (realpath (__DIR__ .'/public/foo.txt ' ));
146147
@@ -185,9 +186,9 @@ public function test_respond_method_sends_response_to_swoole(): void
185186 $ swooleResponse = Mockery::mock ('Swoole\Http\Response ' );
186187
187188 $ swooleResponse ->shouldReceive ('status ' )->once ()->with (200 );
188- $ swooleResponse ->shouldReceive ('header ' )->once ()->with ('Cache-Control ' , 'no-cache, private ' );
189- $ swooleResponse ->shouldReceive ('header ' )->once ()->with ('Content-Type ' , 'text/html ' );
190- $ swooleResponse ->shouldReceive ('header ' )->once ()->with ('Date ' , Mockery::type ('string ' ));
189+ $ swooleResponse ->shouldReceive ('header ' )->once ()->with ('Cache-Control ' , 'no-cache, private ' , true );
190+ $ swooleResponse ->shouldReceive ('header ' )->once ()->with ('Content-Type ' , 'text/html ' , true );
191+ $ swooleResponse ->shouldReceive ('header ' )->once ()->with ('Date ' , Mockery::type ('string ' ), true );
191192 $ swooleResponse ->shouldReceive ('cookie ' )->once ()->with ('new ' , 'value ' , 0 , '/ ' , '' , false , true , 'lax ' );
192193 $ swooleResponse ->shouldReceive ('cookie ' )->once ()->with ('cleared ' , 'deleted ' , Mockery::type ('int ' ), '/ ' , '' , false , true , 'lax ' );
193194 $ swooleResponse ->shouldReceive ('write ' )->with ('Hello World ' );
@@ -210,9 +211,9 @@ public function test_respond_method_send_streamed_response_to_swoole(): void
210211 $ swooleResponse = Mockery::mock ('Swoole\Http\Response ' );
211212
212213 $ swooleResponse ->shouldReceive ('status ' )->once ()->with (200 );
213- $ swooleResponse ->shouldReceive ('header ' )->once ()->with ('Cache-Control ' , 'no-cache, private ' );
214- $ swooleResponse ->shouldReceive ('header ' )->once ()->with ('Content-Type ' , 'text/html ' );
215- $ swooleResponse ->shouldReceive ('header ' )->once ()->with ('Date ' , Mockery::type ('string ' ));
214+ $ swooleResponse ->shouldReceive ('header ' )->once ()->with ('Cache-Control ' , 'no-cache, private ' , true );
215+ $ swooleResponse ->shouldReceive ('header ' )->once ()->with ('Content-Type ' , 'text/html ' , true );
216+ $ swooleResponse ->shouldReceive ('header ' )->once ()->with ('Date ' , Mockery::type ('string ' ), true );
216217 $ swooleResponse ->shouldReceive ('write ' )->once ()->with ('Hello World ' );
217218 $ swooleResponse ->shouldReceive ('end ' )->once ();
218219
@@ -231,9 +232,9 @@ public function test_respond_method_with_laravel_specific_status_code_sends_resp
231232 $ swooleResponse = Mockery::mock ('Swoole\Http\Response ' );
232233
233234 $ swooleResponse ->shouldReceive ('status ' )->once ()->with (419 , 'Page Expired ' );
234- $ swooleResponse ->shouldReceive ('header ' )->once ()->with ('Cache-Control ' , 'no-cache, private ' );
235- $ swooleResponse ->shouldReceive ('header ' )->once ()->with ('Content-Type ' , 'text/html ' );
236- $ swooleResponse ->shouldReceive ('header ' )->once ()->with ('Date ' , Mockery::type ('string ' ));
235+ $ swooleResponse ->shouldReceive ('header ' )->once ()->with ('Cache-Control ' , 'no-cache, private ' , true );
236+ $ swooleResponse ->shouldReceive ('header ' )->once ()->with ('Content-Type ' , 'text/html ' , true );
237+ $ swooleResponse ->shouldReceive ('header ' )->once ()->with ('Date ' , Mockery::type ('string ' ), true );
237238 $ swooleResponse ->shouldReceive ('write ' )->with ('Hello World ' );
238239 $ swooleResponse ->shouldReceive ('end ' )->once ();
239240
@@ -290,9 +291,9 @@ public function test_respond_method_send_not_chunked_response_to_swoole(): void
290291 $ swooleResponse = Mockery::mock (SwooleResponse::class);
291292
292293 $ swooleResponse ->shouldReceive ('status ' )->once ()->with (200 );
293- $ swooleResponse ->shouldReceive ('header ' )->once ()->with ('Cache-Control ' , 'no-cache, private ' );
294- $ swooleResponse ->shouldReceive ('header ' )->once ()->with ('Content-Type ' , 'text/html ' );
295- $ swooleResponse ->shouldReceive ('header ' )->once ()->with ('Date ' , Mockery::type ('string ' ));
294+ $ swooleResponse ->shouldReceive ('header ' )->once ()->with ('Cache-Control ' , 'no-cache, private ' , true );
295+ $ swooleResponse ->shouldReceive ('header ' )->once ()->with ('Content-Type ' , 'text/html ' , true );
296+ $ swooleResponse ->shouldReceive ('header ' )->once ()->with ('Date ' , Mockery::type ('string ' ), true );
296297 $ swooleResponse ->shouldReceive ('write ' )->never ();
297298 $ swooleResponse ->shouldReceive ('end ' )->once ()->with ('Hello World ' );
298299
@@ -311,9 +312,9 @@ public function test_respond_method_send_chunked_response_to_swoole(): void
311312 $ swooleResponse = Mockery::mock ('Swoole\Http\Response ' );
312313
313314 $ swooleResponse ->shouldReceive ('status ' )->once ()->with (200 );
314- $ swooleResponse ->shouldReceive ('header ' )->once ()->with ('Cache-Control ' , 'no-cache, private ' );
315- $ swooleResponse ->shouldReceive ('header ' )->once ()->with ('Content-Type ' , 'text/html ' );
316- $ swooleResponse ->shouldReceive ('header ' )->once ()->with ('Date ' , Mockery::type ('string ' ));
315+ $ swooleResponse ->shouldReceive ('header ' )->once ()->with ('Cache-Control ' , 'no-cache, private ' , true );
316+ $ swooleResponse ->shouldReceive ('header ' )->once ()->with ('Content-Type ' , 'text/html ' , true );
317+ $ swooleResponse ->shouldReceive ('header ' )->once ()->with ('Date ' , Mockery::type ('string ' ), true );
317318 $ swooleResponse ->shouldReceive ('write ' )->once ()->with ('Hello ' );
318319 $ swooleResponse ->shouldReceive ('write ' )->once ()->with ('World ' );
319320 $ swooleResponse ->shouldReceive ('end ' )->once ();
@@ -324,4 +325,28 @@ public function test_respond_method_send_chunked_response_to_swoole(): void
324325 'swooleResponse ' => $ swooleResponse ,
325326 ]), new OctaneResponse ($ response ));
326327 }
328+
329+ /** @doesNotPerformAssertions @test */
330+ public function test_respond_method_preserves_header_formatting_if_configured (): void
331+ {
332+ $ this ->createApplication ();
333+
334+ $ client = new SwooleClient ;
335+
336+ Config::set ('octane.swoole.format_headers ' , false );
337+
338+ $ swooleResponse = Mockery::mock ('Swoole\Http\Response ' );
339+
340+ $ swooleResponse ->shouldReceive ('status ' )->once ()->with (200 );
341+ $ swooleResponse ->shouldReceive ('header ' )->once ()->with ('Cache-Control ' , 'no-cache, private ' , false );
342+ $ swooleResponse ->shouldReceive ('header ' )->once ()->with ('Content-Type ' , 'text/html ' , false );
343+ $ swooleResponse ->shouldReceive ('header ' )->once ()->with ('Date ' , Mockery::type ('string ' ), false );
344+ $ swooleResponse ->shouldReceive ('end ' )->once ();
345+
346+ $ response = new Response (null , 200 , ['Content-Type ' => 'text/html ' ]);
347+
348+ $ client ->respond (new RequestContext ([
349+ 'swooleResponse ' => $ swooleResponse ,
350+ ]), new OctaneResponse ($ response ));
351+ }
327352}
0 commit comments