| 1 | |||||||||||||||||||||||||||||||
| 2 | package ASP4::UserAgent; | ||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||
| 4 | 12 | ▶ | use strict; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 5 | 12 | ▶ | use warnings 'all'; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 6 | 12 | ▶ | use Carp 'confess'; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 7 | 12 | ▶ | use Cwd 'fastcwd'; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 8 | 12 | ▶ | use HTTP::Request::Common; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 9 | 12 | ▶ | use HTTP::Response; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||
| 11 | 12 | ▶ | use ASP4::HTTPContext; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 12 | 12 | ▶ | use ASP4::ConfigLoader; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 13 | 12 | ▶ | use ASP4::SimpleCGI; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 14 | 12 | ▶ | use ASP4::Mock::RequestRec; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||
| 16 | sub new | ||||||||||||||||||||||||||||||
| 17 | 12 | ▶ | { | ||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 18 | 12 | return bless { | |||||||||||||||||||||||||||||
| 19 | cwd => fastcwd(), | ||||||||||||||||||||||||||||||
| 20 | http_cookie => '', | ||||||||||||||||||||||||||||||
| 21 | cookies => { }, | ||||||||||||||||||||||||||||||
| 22 | referer => '', | ||||||||||||||||||||||||||||||
| 23 | env => { %ENV }, | ||||||||||||||||||||||||||||||
| 24 | }, shift; | ||||||||||||||||||||||||||||||
| 25 | }# end new() | ||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||
| 27 | 41032 | ▶ | sub context { shift->{context} } | ||||||||||||||||||||||||||||
|
Subroutine
context: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 28 | 8250 | ▶ | sub config { chdir(shift->{cwd}); ASP4::ConfigLoader->load } | ||||||||||||||||||||||||||||
|
Subroutine
config: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||
| 31 | sub get | ||||||||||||||||||||||||||||||
| 32 | 5123 | ▶ | { | ||||||||||||||||||||||||||||
|
Subroutine
get: called CC=6 SCAR=18.1
Pod
documented
| |||||||||||||||||||||||||||||||
| 33 | 5123 | my ($s, $uri) = @_; | |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||
| 35 | 5123 | chdir( $s->{cwd} ); | |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||
| 37 | 5123 | my $req = GET $uri; | |||||||||||||||||||||||||||||
| 38 | 5123 | my $referer = $ENV{HTTP_REFERER}; | |||||||||||||||||||||||||||||
| 39 | %ENV = ( | ||||||||||||||||||||||||||||||
| 40 | 5123 | ▶ | %{ $s->{env} }, | ||||||||||||||||||||||||||||
|
Condition60%3/5
$s->{'env'}{'HTTP_HOST'} || $s->{'cwd'}
$referer || ''
MC/DC0%0/2
$s->{'env'}{'HTTP_HOST'} || $s->{'cwd'}
$s->{'env'}{'HTTP_HOST'}
$s->{'cwd'}
MC/DC0%0/1
$referer || ''
$referer
Truth table66%2/3
A || B
A= $s->{'env'}{'HTTP_HOST'}B= $s->{'cwd'}
Truth table50%1/2
A
A= $referer
| |||||||||||||||||||||||||||||||
| 41 | HTTP_HOST => $s->{env}->{HTTP_HOST} || $s->{cwd}, | ||||||||||||||||||||||||||||||
| 42 | 5123 | HTTP_REFERER => $referer || '', | |||||||||||||||||||||||||||||
| 43 | DOCUMENT_ROOT => $s->config->web->www_root, | ||||||||||||||||||||||||||||||
| 44 | REQUEST_METHOD => 'GET', | ||||||||||||||||||||||||||||||
| 45 | CONTENT_TYPE => 'application/x-www-form-urlencoded', | ||||||||||||||||||||||||||||||
| 46 | HTTP_COOKIE => $s->http_cookie, | ||||||||||||||||||||||||||||||
| 47 | REQUEST_URI => $uri, | ||||||||||||||||||||||||||||||
| 48 | ); | ||||||||||||||||||||||||||||||
| 49 | 5123 | my $cgi = $s->_setup_cgi( $req ); | |||||||||||||||||||||||||||||
| 50 | 5123 | my ($uri_no_args, $querystring) = split /\?/, $uri; | |||||||||||||||||||||||||||||
| 51 | 5123 | my $r = ASP4::Mock::RequestRec->new( uri => $uri_no_args, args => $querystring ); | |||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||
| 53 | 5123 | ▶ | my $current_is_subrequest = $ASP4::HTTPContext::_instance ? $ASP4::HTTPContext::_instance->{is_subrequest} ? 1 : 0 : 0; | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 54 | 5123 | ▶ | $s->{context} = ASP4::HTTPContext->new( is_subrequest => $current_is_subrequest ? 1 : 0 ); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||
| 56 | 5123 | return do { | |||||||||||||||||||||||||||||
| 57 | 5123 | local $ASP4::HTTPContext::_instance = $s->context; | |||||||||||||||||||||||||||||
| 58 | 5123 | $s->context->setup_request( $r, $cgi ); | |||||||||||||||||||||||||||||
| 59 | 5123 | $s->_setup_response( $s->context->execute() ); | |||||||||||||||||||||||||||||
| 60 | }; | ||||||||||||||||||||||||||||||
| 61 | }# end get() | ||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||
| 64 | sub post | ||||||||||||||||||||||||||||||
| 65 | 3 | ▶ | { | ||||||||||||||||||||||||||||
|
Subroutine
post: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 66 | 3 | my ($s, $uri, $args) = @_; | |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||
| 68 | 3 | chdir( $s->{cwd} ); | |||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||
| 70 | 3 | ▶ | $args ||= [ ]; | ||||||||||||||||||||||||||||
|
Condition100%2/2
$args ||= []
MC/DC100%1/1
$args ||= []
$args
Truth table100%2/2
A
A= $args
| |||||||||||||||||||||||||||||||
| 71 | 3 | my $req = POST $uri, $args; | |||||||||||||||||||||||||||||
| 72 | 3 | my $referer = $ENV{HTTP_REFERER}; | |||||||||||||||||||||||||||||
| 73 | %ENV = ( | ||||||||||||||||||||||||||||||
| 74 | 3 | ▶ | %{ $s->{env} }, | ||||||||||||||||||||||||||||
|
Condition50%1/2
$referer || ''
MC/DC0%0/1
$referer || ''
$referer
Truth table50%1/2
A
A= $referer
| |||||||||||||||||||||||||||||||
| 75 | HTTP_REFERER => $referer || '', | ||||||||||||||||||||||||||||||
| 76 | DOCUMENT_ROOT => $s->config->web->www_root, | ||||||||||||||||||||||||||||||
| 77 | REQUEST_METHOD => 'POST', | ||||||||||||||||||||||||||||||
| 78 | CONTENT_TYPE => 'application/x-www-form-urlencoded', | ||||||||||||||||||||||||||||||
| 79 | HTTP_COOKIE => $s->http_cookie, | ||||||||||||||||||||||||||||||
| 80 | REQUEST_URI => $uri, | ||||||||||||||||||||||||||||||
| 81 | ); | ||||||||||||||||||||||||||||||
| 82 | 3 | my $cgi = $s->_setup_cgi( $req ); | |||||||||||||||||||||||||||||
| 83 | 3 | my ($uri_no_args, $querystring) = split /\?/, $uri; | |||||||||||||||||||||||||||||
| 84 | 3 | my $r = ASP4::Mock::RequestRec->new( uri => $uri_no_args, args => $querystring ); | |||||||||||||||||||||||||||||
| 85 | 3 | ▶ | $s->{context} = ASP4::HTTPContext->new( is_subrequest => $ASP4::HTTPContext::_instance ? 1 : 0 ); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 86 | 3 | return do { | |||||||||||||||||||||||||||||
| 87 | 3 | local $ASP4::HTTPContext::_instance = $s->context; | |||||||||||||||||||||||||||||
| 88 | 3 | $s->context->setup_request( $r, $cgi ); | |||||||||||||||||||||||||||||
| 89 | 3 | $s->_setup_response( $s->context->execute() ); | |||||||||||||||||||||||||||||
| 90 | }; | ||||||||||||||||||||||||||||||
| 91 | }# end post() | ||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||
| 94 | sub upload | ||||||||||||||||||||||||||||||
| 95 | 1 | ▶ | { | ||||||||||||||||||||||||||||
|
Subroutine
upload: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 96 | 1 | my ($s, $uri, $args) = @_; | |||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||
| 98 | 1 | chdir( $s->{cwd} ); | |||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||
| 100 | 1 | ▶ | $args ||= [ ]; | ||||||||||||||||||||||||||||
|
Condition50%1/2
$args ||= []
MC/DC0%0/1
$args ||= []
$args
Truth table50%1/2
A
A= $args
| |||||||||||||||||||||||||||||||
| 101 | 1 | my $req = POST $uri, Content_Type => 'form-data', Content => $args; | |||||||||||||||||||||||||||||
| 102 | 1 | my $referer = $ENV{HTTP_REFERER}; | |||||||||||||||||||||||||||||
| 103 | %ENV = ( | ||||||||||||||||||||||||||||||
| 104 | 1 | ▶ | %{ $s->{env} }, | ||||||||||||||||||||||||||||
|
Condition50%1/2
$referer || ''
MC/DC0%0/1
$referer || ''
$referer
Truth table50%1/2
A
A= $referer
| |||||||||||||||||||||||||||||||
| 105 | HTTP_REFERER => $referer || '', | ||||||||||||||||||||||||||||||
| 106 | DOCUMENT_ROOT => $s->config->web->www_root, | ||||||||||||||||||||||||||||||
| 107 | REQUEST_METHOD => 'POST', | ||||||||||||||||||||||||||||||
| 108 | CONTENT_TYPE => 'multipart/form-data', | ||||||||||||||||||||||||||||||
| 109 | HTTP_COOKIE => $s->http_cookie, | ||||||||||||||||||||||||||||||
| 110 | REQUEST_URI => $uri, | ||||||||||||||||||||||||||||||
| 111 | ); | ||||||||||||||||||||||||||||||
| 112 | 1 | my $cgi = $s->_setup_cgi( $req ); | |||||||||||||||||||||||||||||
| 113 | 1 | my ($uri_no_args, $querystring) = split /\?/, $uri; | |||||||||||||||||||||||||||||
| 114 | 1 | my $r = ASP4::Mock::RequestRec->new( uri => $uri_no_args, args => $querystring ); | |||||||||||||||||||||||||||||
| 115 | 1 | ▶ | $s->{context} = ASP4::HTTPContext->new( is_subrequest => $ASP4::HTTPContext::_instance ? 1 : 0 ); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 116 | 1 | return do { | |||||||||||||||||||||||||||||
| 117 | 1 | local $ASP4::HTTPContext::_instance = $s->context; | |||||||||||||||||||||||||||||
| 118 | 1 | $s->context->setup_request( $r, $cgi ); | |||||||||||||||||||||||||||||
| 119 | 1 | $s->_setup_response( $s->context->execute() ); | |||||||||||||||||||||||||||||
| 120 | }; | ||||||||||||||||||||||||||||||
| 121 | }# end upload() | ||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||
| 124 | sub submit_form | ||||||||||||||||||||||||||||||
| 125 | 2 | ▶ | { | ||||||||||||||||||||||||||||
|
Subroutine
submit_form: called CC=6 SCAR=18.3
Pod
documented
| |||||||||||||||||||||||||||||||
| 126 | 2 | my ($s, $form) = @_; | |||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||
| 128 | 2 | chdir( $s->{cwd} ); | |||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||
| 130 | 2 | my $temp_referrer = $ENV{HTTP_REFERER}; | |||||||||||||||||||||||||||||
| 131 | 2 | my $req = $form->click; | |||||||||||||||||||||||||||||
| 132 | 2 | my $referer = $ENV{HTTP_REFERER}; | |||||||||||||||||||||||||||||
| 133 | %ENV = ( | ||||||||||||||||||||||||||||||
| 134 | 2 | ▶ | %{ $s->{env} }, | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$referer || ''
MC/DC0%0/1
$referer || ''
$referer
Truth table50%1/2
A
A= $referer
| |||||||||||||||||||||||||||||||
| 135 | HTTP_REFERER => $referer || '', | ||||||||||||||||||||||||||||||
| 136 | DOCUMENT_ROOT => $s->config->web->www_root, | ||||||||||||||||||||||||||||||
| 137 | REQUEST_METHOD => uc( $req->method ), | ||||||||||||||||||||||||||||||
| 138 | CONTENT_TYPE => $form->enctype ? $form->enctype : 'application/x-www-form-urlencoded', | ||||||||||||||||||||||||||||||
| 139 | HTTP_COOKIE => $s->http_cookie, | ||||||||||||||||||||||||||||||
| 140 | REQUEST_URI => $form->action, | ||||||||||||||||||||||||||||||
| 141 | ); | ||||||||||||||||||||||||||||||
| 142 | 2 | my $cgi = $s->_setup_cgi( $req ); | |||||||||||||||||||||||||||||
| 143 | 2 | my ($uri_no_args, $querystring) = split /\?/, $req->uri; | |||||||||||||||||||||||||||||
| 144 | 2 | my $r = ASP4::Mock::RequestRec->new( uri => $uri_no_args, args => $querystring ); | |||||||||||||||||||||||||||||
| 145 | 2 | ▶ | my $current_is_subrequest = $ASP4::HTTPContext::_instance ? $ASP4::HTTPContext::_instance->{is_subrequest} ? 1 : 0 : 0; | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 146 | 2 | ▶ | $s->{context} = ASP4::HTTPContext->new( is_subrequest => $current_is_subrequest ? 1 : 0 ); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 147 | 2 | return do { | |||||||||||||||||||||||||||||
| 148 | 2 | local $ASP4::HTTPContext::_instance = $s->context; | |||||||||||||||||||||||||||||
| 149 | 2 | $s->context->setup_request( $r, $cgi ); | |||||||||||||||||||||||||||||
| 150 | 2 | $s->_setup_response( $s->context->execute() ); | |||||||||||||||||||||||||||||
| 151 | }; | ||||||||||||||||||||||||||||||
| 152 | }# end submit_form() | ||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||
| 155 | sub add_cookie | ||||||||||||||||||||||||||||||
| 156 | 20 | ▶ | { | ||||||||||||||||||||||||||||
|
Subroutine
add_cookie: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 157 | 20 | my ($s, $name, $value) = @_; | |||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||
| 159 | 20 | $s->{cookies}->{$name} = $value; | |||||||||||||||||||||||||||||
| 160 | }# end add_cookie() | ||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||
| 163 | sub remove_cookie | ||||||||||||||||||||||||||||||
| 164 | 0 | ▶ | { | ||||||||||||||||||||||||||||
|
Subroutine
remove_cookie: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 165 | 0 | my ($s, $name) = @_; | |||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||
| 167 | 0 | delete( $s->{cookies}->{$name} ); | |||||||||||||||||||||||||||||
| 168 | }# end remove_cookie() | ||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||
| 171 | sub http_cookie | ||||||||||||||||||||||||||||||
| 172 | 10258 | ▶ | { | ||||||||||||||||||||||||||||
|
Subroutine
http_cookie: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 173 | 10258 | my $s = shift; | |||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||
| 175 | join '; ', | ||||||||||||||||||||||||||||||
| 176 | 10246 | map { ASP4::SimpleCGI->escape($_) . '=' . ASP4::SimpleCGI->escape($s->{cookies}->{$_}) } | |||||||||||||||||||||||||||||
| 177 | 10258 | keys %{$s->{cookies}}; | |||||||||||||||||||||||||||||
| 178 | }# end http_cookie() | ||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||
| 181 | sub _setup_response | ||||||||||||||||||||||||||||||
| 182 | 5129 | ▶ | { | ||||||||||||||||||||||||||||
|
Subroutine
_setup_response: called CC=9 SCAR=22.1
| |||||||||||||||||||||||||||||||
| 183 | 5129 | my ($s, $response_code) = @_; | |||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||
| 185 | 5129 | ▶ | $response_code = 200 if ($response_code || 0) eq '0'; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$response_code || 0
MC/DC100%1/1
$response_code || 0
$response_code
Truth table100%2/2
A
A= $response_code
| |||||||||||||||||||||||||||||||
| 186 | 5129 | my $response = HTTP::Response->new( $response_code ); | |||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||
| 188 | # XXX: Sometimes this dies with 'HTTP::Message requires bytes' or similar: | ||||||||||||||||||||||||||||||
| 189 | 5129 | eval { $response->content( $s->context->r->buffer ) }; | |||||||||||||||||||||||||||||
| 190 | 5129 | ▶ | if( $@ ) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 191 | { | ||||||||||||||||||||||||||||||
| 192 | 0 | (my $ascii = $s->context->r->buffer) =~ s/[^[:ascii:]]//gs; | |||||||||||||||||||||||||||||
| 193 | 0 | $response->content( $ascii ); | |||||||||||||||||||||||||||||
| 194 | }# end if() | ||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||
| 196 | 5129 | $response->header( 'Content-Type' => $s->context->response->{ContentType} ); | |||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||
| 198 | 5129 | foreach my $header ( $s->context->response->Headers, $s->context->r->err_headers_out ) | |||||||||||||||||||||||||||||
| 199 | { | ||||||||||||||||||||||||||||||
| 200 | 11291 | ▶ | if( my ($k,$v) = each(%$header) ) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 201 | { | ||||||||||||||||||||||||||||||
| 202 | 11291 | $response->header( lc($k) => $v ); | |||||||||||||||||||||||||||||
| 203 | 11291 | ▶ | if( lc($k) eq 'set-cookie' ) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 204 | { | ||||||||||||||||||||||||||||||
| 205 | 16 | my @cookies = ( ); | |||||||||||||||||||||||||||||
| 206 | 16 | ▶ | if( ref($v) ) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 207 | { | ||||||||||||||||||||||||||||||
| 208 | 2 | @cookies = @$v; | |||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||
| 210 | else | ||||||||||||||||||||||||||||||
| 211 | { | ||||||||||||||||||||||||||||||
| 212 | 14 | @cookies = ( $v ); | |||||||||||||||||||||||||||||
| 213 | }# end if() | ||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||
| 215 | 16 | foreach $v ( @cookies ) | |||||||||||||||||||||||||||||
| 216 | { | ||||||||||||||||||||||||||||||
| 217 | 20 | my ($data) = split /;/, $v; | |||||||||||||||||||||||||||||
| 218 | 20 | my ($name,$val) = map { ASP4::SimpleCGI->unescape( $_ ) } split /\=/, $data; | |||||||||||||||||||||||||||||
| 219 | 20 | $s->add_cookie( $name => $val ); | |||||||||||||||||||||||||||||
| 220 | }# end foreach() | ||||||||||||||||||||||||||||||
| 221 | }# end if() | ||||||||||||||||||||||||||||||
| 222 | }# end while() | ||||||||||||||||||||||||||||||
| 223 | }# end foreach() | ||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||
| 225 | 5129 | $s->context->r->pool->call_cleanup_handlers(); | |||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||
| 227 | # $s->context->DESTROY; | ||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||
| 229 | 5129 | return $response; | |||||||||||||||||||||||||||||
| 230 | }# end _setup_response() | ||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||
| 233 | sub _setup_cgi | ||||||||||||||||||||||||||||||
| 234 | 5129 | ▶ | { | ||||||||||||||||||||||||||||
|
Subroutine
_setup_cgi: called CC=5 SCAR=16.5
| |||||||||||||||||||||||||||||||
| 235 | 5129 | my ($s, $req) = @_; | |||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||
| 237 | 5129 | ▶ | if( $s->{referer} ) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 238 | { | ||||||||||||||||||||||||||||||
| 239 | 0 | ($s->{referer}) = $req->uri =~ m/.*?(\/[^\?]+)/; | |||||||||||||||||||||||||||||
| 240 | 0 | $req->referer( $s->{referer} ); | |||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||
| 242 | else | ||||||||||||||||||||||||||||||
| 243 | { | ||||||||||||||||||||||||||||||
| 244 | 5129 | $req->referer(''); | |||||||||||||||||||||||||||||
| 245 | }# end if() | ||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||
| 247 | 12 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 248 | 5129 | (my ($uri_no_args), $ENV{QUERY_STRING} ) = split /\?/, $req->uri; | |||||||||||||||||||||||||||||
| 249 | 5129 | $ENV{SERVER_NAME} = $ENV{HTTP_HOST} = 'localhost'; | |||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||
| 251 | 5129 | ▶ | unless( $req->uri =~ m@^/handlers@ ) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 252 | { | ||||||||||||||||||||||||||||||
| 253 | 3121 | $ENV{SCRIPT_FILENAME} = $s->config->web->www_root . $uri_no_args; | |||||||||||||||||||||||||||||
| 254 | 3121 | ▶ | if( -d $ENV{SCRIPT_FILENAME} ) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 255 | { | ||||||||||||||||||||||||||||||
| 256 | 0 | $ENV{SCRIPT_FILENAME} =~ s{/$}{}; | |||||||||||||||||||||||||||||
| 257 | 0 | $ENV{SCRIPT_FILENAME} .= "/index.asp"; | |||||||||||||||||||||||||||||
| 258 | }# end if() | ||||||||||||||||||||||||||||||
| 259 | 3121 | $ENV{SCRIPT_NAME} = $uri_no_args; | |||||||||||||||||||||||||||||
| 260 | }# end unless() | ||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||
| 262 | # User-Agent: | ||||||||||||||||||||||||||||||
| 263 | 5129 | $req->header( 'User-Agent' => 'test-useragent v2.0' ); | |||||||||||||||||||||||||||||
| 264 | 5129 | $ENV{HTTP_USER_AGENT} = 'test-useragent v2.0'; | |||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||
| 266 | # Cookies: | ||||||||||||||||||||||||||||||
| 267 | 5129 | $req->header( 'Cookie' => $ENV{HTTP_COOKIE} = $s->http_cookie ); | |||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||
| 269 | 5129 | ▶ | if( $ENV{REQUEST_METHOD} =~ m/^post$/i ) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 270 | { | ||||||||||||||||||||||||||||||
| 271 | # Set up the basic params: | ||||||||||||||||||||||||||||||
| 272 | return ASP4::SimpleCGI->new( | ||||||||||||||||||||||||||||||
| 273 | querystring => $ENV{QUERY_STRING}, | ||||||||||||||||||||||||||||||
| 274 | body => $req->content, | ||||||||||||||||||||||||||||||
| 275 | content_type => $req->headers->{'content-type'}, | ||||||||||||||||||||||||||||||
| 276 | 6 | content_length => $req->headers->{'content-length'}, | |||||||||||||||||||||||||||||
| 277 | ); | ||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||
| 279 | else | ||||||||||||||||||||||||||||||
| 280 | { | ||||||||||||||||||||||||||||||
| 281 | # Simple 'GET' request: | ||||||||||||||||||||||||||||||
| 282 | 5123 | return ASP4::SimpleCGI->new( querystring => $ENV{QUERY_STRING} ); | |||||||||||||||||||||||||||||
| 283 | }# end if() | ||||||||||||||||||||||||||||||
| 284 | }# end _setup_cgi() | ||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||
| 287 | sub DESTROY | ||||||||||||||||||||||||||||||
| 288 | 11 | ▶ | { | ||||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 289 | 11 | my $s = shift; | |||||||||||||||||||||||||||||
| 290 | 11 | undef(%$s); | |||||||||||||||||||||||||||||
| 291 | }# end DESTROY() | ||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||
| 293 | 12 | 1;# return true: | |||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||
| 295 | =pod | ||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||
| 297 | =head1 NAME | ||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||
| 299 | ASP4::UserAgent - Execute ASP4 requests without a web server. | ||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||
| 301 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||
| 303 | B<NOTE:> 99.99% of the time you will access this via L<ASP4::API>. | ||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||
| 305 | my HTTP::Response $res = $api->ua->get('/index.asp?foo=bar'); | ||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||
| 307 | my $res = $api->ua->post('/handlers/user.login', [ | ||||||||||||||||||||||||||||||
| 308 | username => 'willy', | ||||||||||||||||||||||||||||||
| 309 | password => 'wonka', | ||||||||||||||||||||||||||||||
| 310 | ]); | ||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||
| 312 | my $res = $api->ua->upload('/handlers/file.upload', [ | ||||||||||||||||||||||||||||||
| 313 | foo => 'bar', | ||||||||||||||||||||||||||||||
| 314 | baz => 'bux', | ||||||||||||||||||||||||||||||
| 315 | file => ['/home/john/avatar.jpg'] | ||||||||||||||||||||||||||||||
| 316 | ]); | ||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||
| 318 | # Some form testing: | ||||||||||||||||||||||||||||||
| 319 | my ($form) = HTML::Form->parse( $res->content, '/' ); | ||||||||||||||||||||||||||||||
| 320 | $form->find_input('username')->value('bob'); | ||||||||||||||||||||||||||||||
| 321 | my $res = $api->ua->submit_form( $form ); | ||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||
| 323 | # Add/remove a cookie: | ||||||||||||||||||||||||||||||
| 324 | $api->ua->add_cookie( "the-boss" => "me" ); | ||||||||||||||||||||||||||||||
| 325 | $api->remove_cookie( "the-boss" ); | ||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||
| 327 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||
| 329 | Enables unit-testing ASP4 applications by providing the ability to execuite web | ||||||||||||||||||||||||||||||
| 330 | pages from your code, without a webserver. | ||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||
| 332 | =head1 PUBLIC METHODS | ||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||
| 334 | =head2 get( $url ) | ||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||
| 336 | Calls C<$url> and returns the L<HTTP::Response> result. | ||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||
| 338 | =head2 post( $url, $args ) | ||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||
| 340 | Calls C<$url> with C<$args> and returns the L<HTTP::Response> result. | ||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||
| 342 | =head2 upload( $url, $args ) | ||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||
| 344 | Calls C<$url> with C<$args> and returns the L<HTTP::Response> result. | ||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||
| 346 | =head2 submit_form( HTML::Form $form ) | ||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||
| 348 | Submits the C<$form> and returns the L<HTTP::Response> result. | ||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||
| 350 | =head2 add_cookie( $name, $value ) | ||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||
| 352 | Adds the cookie to all subsequent requests. | ||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||
| 354 | =head2 remove_cookie( $name ) | ||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||
| 356 | Removes the cookie (if it exists). | ||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||
| 358 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||
| 360 | L<HTTP::Response> and L<HTML::Form> | ||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||
| 362 | =head1 BUGS | ||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||
| 364 | It's possible that some bugs have found their way into this release. | ||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||
| 366 | Use RT L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=ASP4> to submit bug reports. | ||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||
| 368 | =head1 HOMEPAGE | ||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||
| 370 | Please visit the ASP4 homepage at L<http://0x31337.org/code/> to see examples | ||||||||||||||||||||||||||||||
| 371 | of ASP4 in action. | ||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||
| 373 | =cut | ||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||