File tree Expand file tree Collapse file tree 4 files changed +72
-38
lines changed
Expand file tree Collapse file tree 4 files changed +72
-38
lines changed Original file line number Diff line number Diff line change @@ -639,6 +639,8 @@ public function send(string $body = ''): void
639639 $ this ->end ();
640640 }
641641
642+ $ this ->sent = true ;
643+
642644 $ this ->disablePayload ();
643645 }
644646
Original file line number Diff line number Diff line change @@ -43,4 +43,17 @@ public function testFile()
4343 $ response = $ this ->client ->call (Client::METHOD_GET , '/humans.txt ' );
4444 $ this ->assertEquals (204 , $ response ['headers ' ]['status-code ' ]);
4545 }
46+
47+ public function testEarlyResponse ()
48+ {
49+ // Ensure response from action is not recieved
50+ $ response = $ this ->client ->call (Client::METHOD_GET , '/early-response ' );
51+ $ this ->assertEquals (200 , $ response ['headers ' ]['status-code ' ]);
52+ $ this ->assertNotEquals ('Action response ' , $ response ['body ' ]);
53+
54+ // 2nd request would catch if action from first ran
55+ $ response = $ this ->client ->call (Client::METHOD_GET , '/early-response ' );
56+ $ this ->assertEquals (200 , $ response ['headers ' ]['status-code ' ]);
57+ $ this ->assertEquals ('Init response. Actioned before: no ' , $ response ['body ' ]);
58+ }
4659}
Original file line number Diff line number Diff line change 4646 $ response ->noContent ();
4747 });
4848
49+
50+ // Endpoints for early response
51+ // Meant to run twice, so init hook can know if action ran
52+ $ earlyResponseAction = 'no ' ;
53+ App::init ()
54+ ->groups (['early-response ' ])
55+ ->inject ('response ' )
56+ ->action (function (Response $ response ) use ($ earlyResponseAction ) {
57+ $ response ->send ('Init response. Actioned before: ' . $ earlyResponseAction );
58+ });
59+
60+ App::get ('/early-response ' )
61+ ->groups (['early-response ' ])
62+ ->inject ('response ' )
63+ ->action (function (Response $ response ) use (&$ earlyResponseAction ) {
64+ $ earlyResponseAction = 'yes ' ;
65+ $ response ->send ('Action response ' );
66+ });
67+
4968$ request = new Request ();
5069$ response = new Response ();
5170
You can’t perform that action at this time.
0 commit comments