/
Request.pm6
67 lines (56 loc) · 1.25 KB
/
Request.pm6
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
use v6;
class FastCGI::Request;
use FastCGI::Constants;
use FastCGI::Protocol;
use FastCGI::Logger;
has $.connection;
has Buf $.input;
has Int $.id;
has Buf $!params;
method param (Buf $param)
{
if $!params.defined
{
$!params ~= $param;
}
else
{
$!params = $param;
}
}
method in (Buf $stdin)
{
if $!input.defined
{
$!input ~= $stdin;
}
else
{
$!input = $stdin;
}
}
method env
{
my $debug = $.connection.parent.debug;
my $log = FastCGI::Logger.new(:name<R::env>);
## First, parse the environment.
$log.say: "Going to parse params." if $debug;
my %env = parse_params($!params);
$log.say: "Parsed params, adding extra meta data." if $debug;
## Now add some meta data.
%env<fastcgi.request> = self;
if $.connection.parent.PSGI
{
%env<psgi.version> = [1,0];
%env<psgi.url_scheme> = 'http'; ## FIXME: detect this.
%env<psgi.multithread> = False;
%env<psgi.multiprocess> = False;
%env<psgi.input> = $.input;
%env<psgi.errors> = $.connection.err;
%env<psgi.run_once> = False;
%env<psgi.nonblocking> = False; ## Allow when NBIO.
%env<psgi.streaming> = False; ## Allow eventually?
}
$log.say: "Added meta data, returning env." if $debug;
return %env;
}