| 1 | package Crop::HTTP::Request::FastCGI; | ||
| 2 | use base qw/ Crop::HTTP::Request /; | ||
| 3 | |||
| 4 | =begin nd | ||
| 5 | Class: Crop::HTTP::Request::FastCGI | ||
| 6 | HTTP request for Fast CGI protocol. | ||
| 7 | =cut | ||
| 8 | |||
| 9 | use v5.14; | ||
| 10 | use warnings; | ||
| 11 | |||
| 12 | use Crop::Server::FastCGI; | ||
| 13 | |||
| 14 | =begin nd | ||
| 15 | Constructor: new (%attr) | ||
| 16 | Decompose a CGI request for separate attributes. | ||
| 17 | |||
| 18 | Parameters: | ||
| 19 | Only one call exists | ||
| 20 | >my $request = Crop::HTTPRequest::FastCGI->new(tik=now()); | ||
| 21 | |||
| 22 | Returns: | ||
| 23 | $self | ||
| 24 | =cut | ||
| 25 | sub new { | ||
| 26 | my $class = shift; | ||
| 27 | |||
| 28 | my $cgi = Crop::Server::FastCGI->instance->cgi; | ||
| 29 | |||
| 30 | my %param = map +($_, scalar $cgi->param($_)), $cgi->param; | ||
| 31 | |||
| 32 | # pack headers | ||
| 33 | my @header = map +("$_:" . $cgi->http($_)), $cgi->http; | ||
| 34 | my $headers; | ||
| 35 | { | ||
| 36 | local $" = "\n"; | ||
| 37 | $headers = "@header"; | ||
| 38 | } | ||
| 39 | |||
| 40 | $class->SUPER::new( | ||
| 41 | content_t => $cgi->content_type, | ||
| 42 | cookie_in => scalar $cgi->cookie('session'), | ||
| 43 | headers => $headers, | ||
| 44 | ip => $cgi->http('X-Real-IP') // $cgi->remote_addr, | ||
| 45 | method => $cgi->request_method, | ||
| 46 | param => \%param, | ||
| 47 | path => $cgi->url(-absolute => 1), | ||
| 48 | qstring => $cgi->request_method eq 'GET' ? $cgi->query_string : undef, | ||
| 49 | referer => $cgi->referer, | ||
| 50 | @_, | ||
| 51 | ); | ||
| 52 | } | ||
| 53 | |||
| 54 | 1; |