| 1 | package POE::Component::FastCGI::Request; | ||||||||||||||||||||||||||||
| 2 | BEGIN { | ||||||||||||||||||||||||||||
| 3 | 2 | ▶ | $POE::Component::FastCGI::Request::VERSION = '0.19'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | } | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use CGI::Util qw(unescape); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use HTTP::Headers; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use base qw/HTTP::Request/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use POE::Component::FastCGI::Response; # for make_response | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | sub new { | ||||||||||||||||||||||||||||
| 15 | 2 | ▶ | my($class, $client, $sessionid, $id, $cgi, $query) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=14.2
Pod
documented
| |||||||||||||||||||||||||||||
| 16 | my $host = defined $cgi->{HTTP_HOST} ? $cgi->{HTTP_HOST} : | ||||||||||||||||||||||||||||
| 17 | 2 | ▶ | $cgi->{SERVER_NAME}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | my $self = $class->SUPER::new( | ||||||||||||||||||||||||||||
| 20 | $cgi->{REQUEST_METHOD}, | ||||||||||||||||||||||||||||
| 21 | "http" . (defined $cgi->{HTTPS} and $cgi->{HTTPS} ? "s" : "") . | ||||||||||||||||||||||||||||
| 22 | "://$host" . $cgi->{REQUEST_URI}, | ||||||||||||||||||||||||||||
| 23 | # Convert CGI style headers back into HTTP style | ||||||||||||||||||||||||||||
| 24 | HTTP::Headers->new( | ||||||||||||||||||||||||||||
| 25 | map { | ||||||||||||||||||||||||||||
| 26 | 2 | ▶ | my $p = $_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $cgi->{'HTTPS'} && ($cgi->{'HTTPS'} ? 's' : '')
MC/DC0%0/2
defined $cgi->{'HTTPS'} && ($cgi->{'HTTPS'} ? 's' : '')
defined $cgi->{'HTTPS'}
($cgi->{'HTTPS'} ? 's' : '')
Truth table33%1/3
A && B
A= defined $cgi->{'HTTPS'}B= ($cgi->{'HTTPS'} ? 's' : '')
| |||||||||||||||||||||||||||||
| 27 | 2 | s/^HTTP_//; | |||||||||||||||||||||||||||
| 28 | 2 | s/_/-/g; | |||||||||||||||||||||||||||
| 29 | 2 | ucfirst(lc $_) => delete $cgi->{$p}; | |||||||||||||||||||||||||||
| 30 | } grep /^HTTP_/, keys %$cgi | ||||||||||||||||||||||||||||
| 31 | ), | ||||||||||||||||||||||||||||
| 32 | $query | ||||||||||||||||||||||||||||
| 33 | ); | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 2 | $self->{client} = $client; | |||||||||||||||||||||||||||
| 36 | 2 | $self->{sessionid} = $sessionid; | |||||||||||||||||||||||||||
| 37 | 2 | $self->{requestid} = $id; | |||||||||||||||||||||||||||
| 38 | 2 | $self->{env} = $cgi; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 2 | return $self; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | sub DESTROY { | ||||||||||||||||||||||||||||
| 44 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | if(not exists $self->{_res}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 0 | warn __PACKAGE__ . " object destroyed without sending response"; | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | sub make_response { | ||||||||||||||||||||||||||||
| 51 | 2 | ▶ | my($self, $response) = @_; | ||||||||||||||||||||||||||
|
Subroutine
make_response: called CC=3 SCAR=15.8
Pod
documented
| |||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 2 | ▶ | if(not defined $response) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | $response = POE::Component::FastCGI::Response->new( | ||||||||||||||||||||||||||||
| 55 | $self->{client}, | ||||||||||||||||||||||||||||
| 56 | $self->{requestid}, | ||||||||||||||||||||||||||||
| 57 | 2 | ); | |||||||||||||||||||||||||||
| 58 | 2 | $self->{_res} = $response; | |||||||||||||||||||||||||||
| 59 | 2 | $response->request($self); | |||||||||||||||||||||||||||
| 60 | 2 | return $response; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 0 | ▶ | if(not $response->isa("POE::Component::FastCGI::Response")) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | 0 | bless $response, "POE::Component::FastCGI::Response"; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 0 | $response->{client} = $self->{client}; | |||||||||||||||||||||||||||
| 68 | 0 | $response->{requestid} = $self->{requestid}; | |||||||||||||||||||||||||||
| 69 | 0 | $response->request($self); | |||||||||||||||||||||||||||
| 70 | 0 | $self->{_res} = $response; | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 0 | return $response; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | sub error { | ||||||||||||||||||||||||||||
| 76 | 0 | ▶ | my($self, $code, $text) = @_; | ||||||||||||||||||||||||||
|
Subroutine
error: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 77 | 0 | warn "Error $code: $text\n"; | |||||||||||||||||||||||||||
| 78 | 0 | $self->make_response->error($code, $text); | |||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | sub env { | ||||||||||||||||||||||||||||
| 82 | 0 | ▶ | my($self, $env) = @_; | ||||||||||||||||||||||||||
|
Subroutine
env: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 83 | 0 | ▶ | if(exists $self->{env}->{$env}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 0 | return $self->{env}->{$env}; | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | 0 | return undef; | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | sub query { | ||||||||||||||||||||||||||||
| 90 | 3 | ▶ | my($self, $param) = @_; | ||||||||||||||||||||||||||
|
Subroutine
query: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 3 | ▶ | if(not exists $self->{_query}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | 2 | ▶ | if($self->method eq 'GET') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 1 | $self->{_query} = _parse(\$self->{env}->{QUERY_STRING}); | |||||||||||||||||||||||||||
| 95 | }else{ | ||||||||||||||||||||||||||||
| 96 | 1 | $self->{_query} = _parse($self->content_ref); | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 3 | ▶ | if(not defined $param) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 101 | 1 | return $self->{_query}; | |||||||||||||||||||||||||||
| 102 | }elsif(exists $self->{_query}->{$param}) { | ||||||||||||||||||||||||||||
| 103 | 1 | return $self->{_query}->{$param}; | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | 1 | return undef; | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | sub cookie { | ||||||||||||||||||||||||||||
| 109 | 1 | ▶ | my($self, $name) = @_; | ||||||||||||||||||||||||||
|
Subroutine
cookie: called CC=5 SCAR=17.8
Pod
documented
| |||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 1 | ▶ | if(not exists $self->{_cookie}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | 1 | ▶ | return undef unless defined $self->header("Cookie"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | 1 | $self->{_cookie} = _parse(\$self->header("Cookie")); | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 1 | ▶ | return $self->{_cookie} if not defined $name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 1 | ▶ | return $self->{_cookie}->{$name} if exists $self->{_cookie}->{$name}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 0 | return undef; | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | sub _parse { | ||||||||||||||||||||||||||||
| 124 | 3 | ▶ | my $string = shift; | ||||||||||||||||||||||||||
|
Subroutine
_parse: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 125 | 3 | my $res = {}; | |||||||||||||||||||||||||||
| 126 | 3 | for(split /[;&] ?/, $$string) { | |||||||||||||||||||||||||||
| 127 | 4 | my($n, $v) = split /=/, $_, 2; | |||||||||||||||||||||||||||
| 128 | 4 | $v = unescape($v); | |||||||||||||||||||||||||||
| 129 | 4 | $res->{$n} = $v; | |||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | 3 | return $res; | |||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 2 | 1; | |||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | =head1 NAME | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | POE::Component::FastCGI::Request - PoCo::FastCGI HTTP Request class | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | use POE::Component::FastCGI::Request; | ||||||||||||||||||||||||||||
| 143 | my $response = POE::Component::FastCGI::Response->new($client, $id, | ||||||||||||||||||||||||||||
| 144 | $cgi, $query); | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | Objects of this class are generally created by L<POE::Component::FastCGI>, | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | C<POE::Component::FastCGI::Request> is a subclass of L<HTTP::Response> | ||||||||||||||||||||||||||||
| 151 | so inherits all of its methods. The includes C<header()> for reading | ||||||||||||||||||||||||||||
| 152 | headers. | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | It also wraps the enviroment variables found in FastCGI requests, so | ||||||||||||||||||||||||||||
| 155 | information such as the client's IP address and the server software | ||||||||||||||||||||||||||||
| 156 | in use is available. | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | =over 4 | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | =item $request = POE::Component::FastCGI::Request->new($client, $id, $cgi, $query) | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | Creates a new C<POE::Component::FastCGI::Request> object. This deletes values | ||||||||||||||||||||||||||||
| 163 | from C<$cgi> while converting it into a L<HTTP::Request> object. | ||||||||||||||||||||||||||||
| 164 | It also assumes $cgi contains certain CGI variables. This generally should | ||||||||||||||||||||||||||||
| 165 | not be used directly, POE::Component::FastCGI creates these objects for you. | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | =item $response = $request->make_response([$response]) | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | Makes a response object for this request or if the optional parameter is | ||||||||||||||||||||||||||||
| 170 | provided turns a normal HTTP::Response object into a | ||||||||||||||||||||||||||||
| 171 | POE::Component::FastCGI::Response object that is linked to this request. | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | =item $request->error($code[, $text]) | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | Sends a HTTP error back to the user. | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | =item $request->env($name) | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | Gets the specified variable out of the CGI environment. | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | eg: | ||||||||||||||||||||||||||||
| 182 | $request->env("REMOTE_ADDR"); | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | =item $request->query([$name]) | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | Gets the value of name from the query (GET or POST data). | ||||||||||||||||||||||||||||
| 187 | Without a parameter returns a hash reference containing all | ||||||||||||||||||||||||||||
| 188 | the query data. | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | =item $request->cookie([$name]) | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | Gets the value of the cookie with name from the request. | ||||||||||||||||||||||||||||
| 193 | Without a parameter returns a hash reference containing all | ||||||||||||||||||||||||||||
| 194 | the cookie data. | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | =back | ||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | Copyright 2005, David Leadbeater L<http://dgl.cx/contact>. All rights reserved. | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | This library is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||
| 203 | it under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | =head1 BUGS | ||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | Please let me know. | ||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | L<POE::Component::FastCGI::Response>, L<HTTP::Request>, | ||||||||||||||||||||||||||||
| 212 | L<POE::Component::FastCGI>, L<POE>. | ||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | =cut | ||||||||||||||||||||||||||||