Skip to content

Commit 5f7979b

Browse files
committed
fix the WebHost to wait the web application only if it returns a task
1 parent 0b3d153 commit 5f7979b

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

lib/Hosting/WebHost.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use DevNet\Common\Configuration\IConfiguration;
1313
use DevNet\Common\Dependency\IServiceProvider;
1414
use DevNet\Common\Dependency\ServiceCollection;
15+
use DevNet\System\Async\Task;
1516
use DevNet\System\Runtime\LauncherProperties;
1617
use DevNet\Web\Diagnostics\ExceptionHandlerMiddleware;
1718
use DevNet\Web\Http\HttpContext;
@@ -73,15 +74,17 @@ public function run(): void
7374
return;
7475
}
7576

76-
$application($context)->wait();
77-
$response = $context->Response;
77+
$result = $application($context);
78+
if ($result instanceof Task) {
79+
$result->wait();
80+
}
7881

7982
// Send the "status line".
80-
$statusLine = $response->getStatusLine();
83+
$statusLine = $context->Response->getStatusLine();
8184
header($statusLine, true);
8285

8386
// Send the response headers from the headers list.
84-
foreach ($response->Headers->getAll() as $name => $values) {
87+
foreach ($context->Response->Headers->getAll() as $name => $values) {
8588
foreach ($values as $value) {
8689
// keep a previous similar header.
8790
header("$name: $value", false);
@@ -90,8 +93,8 @@ public function run(): void
9093

9194
// Output the message body.
9295
if ($context->Response->Body->Length > 0) {
93-
$response->Body->seek(0);
94-
echo $response->Body->read($response->Body->Length);
96+
$context->Response->Body->seek(0);
97+
echo $context->Response->Body->read($context->Response->Body->Length);
9598
}
9699
}
97100

0 commit comments

Comments
 (0)