Skip to content

Commit 6ef79cf

Browse files
committed
Fix Workerman
1 parent 1d3c623 commit 6ef79cf

1 file changed

Lines changed: 36 additions & 21 deletions

File tree

src/Servers/WorkermanServer/start.php

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,43 @@
1414
// Data received
1515
$http_worker->onMessage = static function ($connection, $request) {
1616

17-
return match($request->path()) {
18-
19-
'/echo' => $connection->send( new Response(
20-
200,
21-
['Content-Type' => 'text/plain'],
22-
implode("\n", array_map(fn($name, $value) => "$name: $value", $request->header(), $request->header())))
23-
),
24-
25-
'/cookie' => $connection->send( new Response(
26-
200,
27-
['Content-Type' => 'text/plain'],
28-
implode("\n", array_map(fn($name, $value) => "$name=$value", $request->cookie(), $request->cookie())))
29-
),
30-
31-
'/' => $connection->send( new Response(
32-
200,
33-
['Content-Type' => 'text/plain'],
34-
$request->method() === 'POST' ? $request->rawBody() : 'OK')
35-
),
17+
$path = $request->path();
18+
19+
if ($path === '/echo') {
20+
$body = '';
21+
foreach ($request->header() as $name => $value) {
22+
$body .= "$name: $value\n";
23+
}
24+
;
25+
return $connection->send( new Response(
26+
200,
27+
['Content-Type' => 'text/plain'],
28+
$body
29+
));
30+
}
31+
32+
if ($path === '/cookie') {
33+
$body = '';
34+
foreach ($request->cookie() as $name => $value) {
35+
$body .= "$name=$value\n";
36+
}
3637

37-
default => null,
38-
};
38+
return $connection->send( new Response(
39+
200,
40+
['Content-Type' => 'text/plain'],
41+
$body
42+
));
43+
}
44+
45+
if ($path === '/') {
46+
$body = $request->method() === 'POST' ? $request->rawBody() : 'OK';
47+
48+
return $connection->send( new Response(
49+
200,
50+
['Content-Type' => 'text/plain'],
51+
$body
52+
));
53+
}
3954
};
4055

4156
// Run all workers

0 commit comments

Comments
 (0)