-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathhandlers.php
More file actions
83 lines (73 loc) · 1.8 KB
/
handlers.php
File metadata and controls
83 lines (73 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
use Workerman\Protocols\Http\Response;
function pipeline()
{
return new Response (
200,
['Content-Type' => 'text/plain'],
'ok'
);
}
function baseline11($request)
{
$sum = array_sum($request->get());
if($request->method() === 'POST') {
$sum += $request->rawBody();
}
return new Response (
200,
['Content-Type' => 'text/plain'],
$sum
);
}
function json($request, $count)
{
$m = $request->get('m', 1);
$total = [];
$i = 0;
while ($i < $count) {
$item = JSON_DATA[$i++];
$item['total'] = $item['price'] * $item['quantity'] * $m;
$total[] = $item;
}
$result = json_encode(['items' => $total, 'count' => $count], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
$header = [];
if($encoding = $request->header('accept-encoding', '')) {
if(str_contains($encoding, 'br')) {
$result = brotli_compress($result, 1);
$header = ['Content-Encoding' => 'br'];
} elseif (str_contains($encoding, 'gzip')) {
$result = gzencode($result, 1);
$header = ['Content-Encoding' => 'br'];
}
}
return new Response (
200,
['Content-Type' => 'application/json'] + $header,
$result
);
}
function asyncDb($request)
{
return new Response (
200,
['Content-Type' => 'application/json'],
Pgsql::query(
$request->get('min', 10),
$request->get('max', 50),
$request->get('limit', 50)
)
);
}
function upload($request)
{
return new Response (
200,
['Content-Type' => 'text/plain'],
strlen($request->rawBody())
);
}
function files($request, $path)
{
return new Response()->withFile('/data/static/' . $path);
}