/
config-env.p6w
70 lines (58 loc) · 2.15 KB
/
config-env.p6w
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
#!smackup
use v6;
my $i = 0;
sub check-type(%env, $got, $expected) {
my $err = %env<p6w.errors>;
# fake TAP
# First check if the env is missing
if %env{ $got } :!exists {
$err.emit("not ok {++$i} # checking type of $got");
$err.emit("# value for $got does not exist");
}
# Verify that the env is as expected
if %env{ $got } ~~ $expected {
$err.emit("ok {++$i} # checking type of $got");
}
# Give a nice report if not
else {
$err.emit("not ok {++$i} # checking type of $got");
$err.emit("#\texpected: $expected.perl()");
$err.emit("#\t got: %env{ $got }.WHAT.perl()");
}
}
sub check-config(%env) {
check-type %env, 'p6w.version', Version:D;
check-type %env, 'p6w.errors', Supplier:D;
check-type %env, 'p6w.multithread', Bool:D;
check-type %env, 'p6w.multiprocess', Bool:D;
check-type %env, 'p6w.run-once', Bool:D;
check-type %env, 'p6w.protocol.support', Set:D;
check-type %env, 'p6w.protocol.enabled', Set:D;
}
sub app(%env) {
start {
check-config(%env);
check-type %env, 'REQUEST_METHOD', { $_ ~~ all(Str:D, *.chars > 0) };
check-type %env, 'SCRIPT_NAME', { $_ ~~ all(Str:D, any('', m{^ "/"})) };
check-type %env, 'PATH_INFO', { $_ ~~ all(Str:D, any('', m{^ "/"})) };
check-type %env, 'REQUEST_URI', Str:D;
check-type %env, 'QUERY_STRING', Str:D;
check-type %env, 'SERVER_NAME', { $_ ~~ all(Str:D, *.chars > 0) };
check-type %env, 'SERVER_PORT', { $_ ~~ all(Int:D, * > 0) };
check-type %env, 'SERVER_PROTOCOL', { $_ ~~ all(Str:D, *.chars > 0) };
check-type %env, 'CONTENT_LENGTH', Int;
check-type %env, 'CONTENT_TYPE', Str;
check-type %env, 'p6w.url-scheme', Str:D;
check-type %env, 'p6w.input', Supply:D;
check-type %env, 'p6w.ready', Promise:D;
check-type %env, 'p6w.body.encoding', Str:D;
check-type %env, 'p6w.protocol', Str:D;
my $err = %env<p6w.errors>;
$err.emit: "1..$i";
200, [ Content-Type => 'text/plain' ], [ 'OK' ]
}
}
sub config(%env) returns Callable {
check-config(%env);
&app;
}