| 1 | =head1 NAME | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | CGI::Portable::AdapterSocket - Run under IO::Socket-based Perl server | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | =cut | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | ###################################################################### | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | package CGI::Portable::AdapterSocket; | ||||||||||||||||||||||||||||
| 10 | 1 | require 5.004; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | # Copyright (c) 1999-2004, Darren R. Duncan. All rights reserved. This module | ||||||||||||||||||||||||||||
| 13 | # is free software; you can redistribute it and/or modify it under the same terms | ||||||||||||||||||||||||||||
| 14 | # as Perl itself. However, I do request that this copyright information and | ||||||||||||||||||||||||||||
| 15 | # credits remain attached to the file. If you modify this module and | ||||||||||||||||||||||||||||
| 16 | # redistribute a changed version then please attach a note listing the | ||||||||||||||||||||||||||||
| 17 | # modifications. This module is available "as-is" and the author can not be held | ||||||||||||||||||||||||||||
| 18 | # accountable for any problems resulting from its use. | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 1 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | 1 | $VERSION = '0.50'; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | ###################################################################### | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | =head1 DEPENDENCIES | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | =head2 Perl Version | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 5.004 | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | =head2 Standard Modules | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | IO::Socket -- IO::Socket::INET built in | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | =head2 Nonstandard Modules | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | CGI::Portable 0.50 | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | =cut | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | ###################################################################### | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 1 | ▶ | use IO::Socket; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | ###################################################################### | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | =head2 Content of thin shell "startup_socket.pl" for IO::Socket::INET: | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | #!/usr/bin/perl | ||||||||||||||||||||||||||||
| 54 | use strict; | ||||||||||||||||||||||||||||
| 55 | use warnings; | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | print "[Server $0 starting up]\n"; | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | require CGI::Portable; | ||||||||||||||||||||||||||||
| 60 | my $globals = CGI::Portable->new(); | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | use Cwd; | ||||||||||||||||||||||||||||
| 63 | $globals->file_path_root( cwd() ); # let us default to current working directory | ||||||||||||||||||||||||||||
| 64 | $globals->file_path_delimiter( $^O=~/Mac/i ? ":" : $^O=~/Win/i ? "\\" : "/" ); | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | $globals->set_prefs( 'config.pl' ); | ||||||||||||||||||||||||||||
| 67 | $globals->current_user_path_level( 1 ); | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | require CGI::Portable::AdapterSocket; | ||||||||||||||||||||||||||||
| 70 | my $io = CGI::Portable::AdapterSocket->new(); | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | use IO::Socket; | ||||||||||||||||||||||||||||
| 73 | my $server = IO::Socket::INET->new( | ||||||||||||||||||||||||||||
| 74 | Listen => SOMAXCONN, | ||||||||||||||||||||||||||||
| 75 | LocalAddr => '127.0.0.1', | ||||||||||||||||||||||||||||
| 76 | LocalPort => 1984, | ||||||||||||||||||||||||||||
| 77 | Proto => 'tcp' | ||||||||||||||||||||||||||||
| 78 | ); | ||||||||||||||||||||||||||||
| 79 | die "[Error: can't setup server $0]" unless $server; | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | print "[Server $0 accepting clients]\n"; | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | while( my $client = $server->accept() ) { | ||||||||||||||||||||||||||||
| 84 | printf "%s: [Connect from %s]\n", scalar localtime, $client->peerhost; | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | my $content = $globals->make_new_context(); | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | $io->fetch_user_input( $content, $client ); | ||||||||||||||||||||||||||||
| 89 | $content->call_component( 'DemoAardvark' ); | ||||||||||||||||||||||||||||
| 90 | $io->send_user_output( $content, $client ); | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | close $client; | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | printf "%s http://%s:%s%s %s\n", $content->request_method, | ||||||||||||||||||||||||||||
| 95 | $content->server_domain, $content->server_port, | ||||||||||||||||||||||||||||
| 96 | $content->user_path_string, $content->http_status_code; | ||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 1; | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | This Perl 5 object class is an adapter for CGI::Portable that takes care of the | ||||||||||||||||||||||||||||
| 104 | details for gathering user input and sending user output when this Perl script | ||||||||||||||||||||||||||||
| 105 | is the HTTP server itself, and IO::Socket (IO::Socket::INET) is being used for | ||||||||||||||||||||||||||||
| 106 | networking with the HTTP client. | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | =head1 SYNTAX | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | This class does not export any functions or methods, so you need to call them | ||||||||||||||||||||||||||||
| 111 | using object notation. This means using B<Class-E<gt>function()> for functions | ||||||||||||||||||||||||||||
| 112 | and B<$object-E<gt>method()> for methods. If you are inheriting this class for | ||||||||||||||||||||||||||||
| 113 | your own modules, then that often means something like B<$self-E<gt>method()>. | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | =head1 FUNCTIONS AND METHODS | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | =head2 new() | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | This function creates a new CGI::Portable::AdapterSocket object and returns it. | ||||||||||||||||||||||||||||
| 120 | The new object has no properties, but only methods. | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | =cut | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | ###################################################################### | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 127 | 0 | my $class = shift( @_ ); | |||||||||||||||||||||||||||
| 128 | 0 | ▶ | my $self = bless( {}, ref($class) || $class ); | ||||||||||||||||||||||||||
|
Condition0%0/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table0%0/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||
| 129 | 0 | return( $self ); | |||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | ###################################################################### | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | =head2 fetch_user_input( GLOBALS, CLIENT ) | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | This method takes a CGI::Portable object as its first argument, GLOBALS, and | ||||||||||||||||||||||||||||
| 137 | feeds it all of the HTTP request and user input details that it can gather. | ||||||||||||||||||||||||||||
| 138 | The second argument, CLIENT, is an IO::Socket::INET object which is the client | ||||||||||||||||||||||||||||
| 139 | we will be getting our input from. | ||||||||||||||||||||||||||||
| 140 | The user_path() is always initialized from the requested uri by this method; | ||||||||||||||||||||||||||||
| 141 | if you want it to be from a query param then you can update it yourself later. | ||||||||||||||||||||||||||||
| 142 | For debugging purposes, this method returns two strings containing the | ||||||||||||||||||||||||||||
| 143 | un-parsed HTTP request headers and body respectively, should you want to inspect | ||||||||||||||||||||||||||||
| 144 | them for yourself later. | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | =cut | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | ###################################################################### | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 0 | ▶ | sub fetch_user_input { | ||||||||||||||||||||||||||
|
Subroutine
fetch_user_input: not called CC=25 SCAR=64.8
Pod
documented
| |||||||||||||||||||||||||||||
| 151 | 0 | my ($self, $globals, $client) = @_; | |||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 0 | ▶ | $globals->server_ip( $client->sockhost() || '127.0.0.1' ); # number | ||||||||||||||||||||||||||
|
Condition0%0/2
$client->sockhost || '127.0.0.1'
MC/DC0%0/1
$client->sockhost || '127.0.0.1'
$client->sockhost
Truth table0%0/2
A
A= $client->sockhost
| |||||||||||||||||||||||||||||
| 154 | 0 | ▶ | $globals->server_domain( $client->sockaddr() || 'localhost' ); # domain | ||||||||||||||||||||||||||
|
Condition0%0/2
$client->sockaddr || 'localhost'
MC/DC0%0/1
$client->sockaddr || 'localhost'
$client->sockaddr
Truth table0%0/2
A
A= $client->sockaddr
| |||||||||||||||||||||||||||||
| 155 | 0 | ▶ | $globals->server_port( $client->sockport() || 80 ); | ||||||||||||||||||||||||||
|
Condition0%0/2
$client->sockport || 80
MC/DC0%0/1
$client->sockport || 80
$client->sockport
Truth table0%0/2
A
A= $client->sockport
| |||||||||||||||||||||||||||||
| 156 | 0 | ▶ | $globals->client_ip( $client->peerhost() || '127.0.0.1' ); # number | ||||||||||||||||||||||||||
|
Condition0%0/2
$client->peerhost || '127.0.0.1'
MC/DC0%0/1
$client->peerhost || '127.0.0.1'
$client->peerhost
Truth table0%0/2
A
A= $client->peerhost
| |||||||||||||||||||||||||||||
| 157 | 0 | ▶ | $globals->client_domain( $client->peeraddr() || $client->peerhost() || | ||||||||||||||||||||||||||
|
Condition0%0/5
$client->peeraddr || $client->peerhost || 'localhost'
$client->peeraddr or $client->peerhost
MC/DC0%0/2
$client->peeraddr || $client->peerhost || 'localhost'
$client->peeraddr
$client->peerhost
Truth table0%0/3
A or B
A= $client->peeraddrB= $client->peerhost
| |||||||||||||||||||||||||||||
| 158 | 'localhost' ); # domain | ||||||||||||||||||||||||||||
| 159 | 0 | $globals->client_port( $client->peerport() ); | |||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 0 | my $host = $globals->server_domain(); | |||||||||||||||||||||||||||
| 162 | 0 | my $port = $globals->server_port(); | |||||||||||||||||||||||||||
| 163 | 0 | ▶ | $globals->url_base( 'http://'.$host.($port != 80 ? ":$port" : '') ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 0 | my $endl = "\015\012"; # cr + lf | |||||||||||||||||||||||||||
| 166 | 0 | local $\ = $endl.$endl; | |||||||||||||||||||||||||||
| 167 | 0 | local $/ = $endl.$endl; | |||||||||||||||||||||||||||
| 168 | 0 | my $raw_http_headers = <$client>; | |||||||||||||||||||||||||||
| 169 | 0 | my ($request, @headers_in) = grep( /\w/, split( $endl, $raw_http_headers ) ); | |||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | 0 | my ($method, $uri, $protocol) = grep( /\S/, split( /\s/, $request ) ); | |||||||||||||||||||||||||||
| 172 | 0 | ▶ | $globals->request_method( $method || 'GET' ); | ||||||||||||||||||||||||||
|
Condition0%0/2
$method || 'GET'
MC/DC0%0/1
$method || 'GET'
$method
Truth table0%0/2
A
A= $method
| |||||||||||||||||||||||||||||
| 173 | 0 | ▶ | $globals->request_uri( $uri || '/' ); | ||||||||||||||||||||||||||
|
Condition0%0/2
$uri || '/'
MC/DC0%0/1
$uri || '/'
$uri
Truth table0%0/2
A
A= $uri
| |||||||||||||||||||||||||||||
| 174 | 0 | ▶ | $globals->request_protocol( $protocol || 'HTTP/1.0' ); | ||||||||||||||||||||||||||
|
Condition0%0/2
$protocol || 'HTTP/1.0'
MC/DC0%0/1
$protocol || 'HTTP/1.0'
$protocol
Truth table0%0/2
A
A= $protocol
| |||||||||||||||||||||||||||||
| 175 | 0 | my ($path, $query) = split( /\?/, $uri ); | |||||||||||||||||||||||||||
| 176 | 0 | $globals->user_path( $self->_uri_unescape( $path ) ); | |||||||||||||||||||||||||||
| 177 | 0 | $globals->user_query( $query ); | |||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | 0 | my $content_length = 0; | |||||||||||||||||||||||||||
| 180 | 0 | foreach my $header_in (@headers_in) { | |||||||||||||||||||||||||||
| 181 | 0 | my ($key, $value) = split( ": ", $header_in ); | |||||||||||||||||||||||||||
| 182 | 0 | $key = lc( $key ); | |||||||||||||||||||||||||||
| 183 | 0 | ▶ | $key eq 'host' and do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$key eq "host" and do {
() = split(/:/, $value, 3);
$hdomain and $globals->server_domain($hdomain);
$hport and $globals->server_port($hport)
}
MC/DC0%0/2
$key eq "host" and do {
() = split(/:/, $value, 3);
$hdomain and $globals->server_domain($hdomain);
$hport and $globals->server_port($hport)
}
$key eq "host"
do {
() = split(/:/, $value, 3);
$hdomain and $globals->server_domain($hdomain);
$hport and $globals->server_port($hport)
}
Truth table0%0/3
A and B
A= $key eq "host"B= do {
() = split(/:/, $value, 3);
$hdomain and $globals->server_domain($hdomain);
$hport and $globals->server_port($hport)
}
| |||||||||||||||||||||||||||||
| 184 | 0 | my ($hdomain, $hport) = split( ":", $value ); | |||||||||||||||||||||||||||
| 185 | 0 | ▶ | $hdomain and $globals->server_domain( $hdomain ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 186 | 0 | ▶ | $hport and $globals->server_port( $hport ); | ||||||||||||||||||||||||||
|
Condition0%0/3
$hport && $globals->server_port($hport)
MC/DC0%0/2
$hport && $globals->server_port($hport)
$hport
$globals->server_port($hport)
Truth table0%0/3
A && B
A= $hportB= $globals->server_port($hport)
| |||||||||||||||||||||||||||||
| 187 | } and next; | ||||||||||||||||||||||||||||
| 188 | 0 | ▶ | $key eq 'referer' and | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$key eq "referer" and $globals->referer($self->_uri_unescape($value))
MC/DC0%0/2
$key eq "referer" and $globals->referer($self->_uri_unescape($value))
$key eq "referer"
$globals->referer($self->_uri_unescape($value))
Truth table0%0/3
A and B
A= $key eq "referer"B= $globals->referer($self->_uri_unescape($value))
| |||||||||||||||||||||||||||||
| 189 | $globals->referer( $self->_uri_unescape( $value ) ) and next; | ||||||||||||||||||||||||||||
| 190 | 0 | ▶ | $key eq 'user-agent' and $globals->user_agent( $value ) and next; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$key eq "user-agent" and $globals->user_agent($value)
MC/DC0%0/2
$key eq "user-agent" and $globals->user_agent($value)
$key eq "user-agent"
$globals->user_agent($value)
Truth table0%0/3
A and B
A= $key eq "user-agent"B= $globals->user_agent($value)
| |||||||||||||||||||||||||||||
| 191 | 0 | ▶ | $key eq 'cookie' and $globals->user_cookies( $value ) and next; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$key eq "cookie" and $globals->user_cookies($value)
MC/DC0%0/2
$key eq "cookie" and $globals->user_cookies($value)
$key eq "cookie"
$globals->user_cookies($value)
Truth table0%0/3
A and B
A= $key eq "cookie"B= $globals->user_cookies($value)
| |||||||||||||||||||||||||||||
| 192 | 0 | ▶ | $key =~ /length/ and $content_length = $value and next; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$key =~ /length/ and $content_length = $value
MC/DC0%0/2
$key =~ /length/ and $content_length = $value
$key =~ /length/
$content_length = $value
Truth table0%0/3
A and B
A= $key =~ /length/B= $content_length = $value
| |||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | 0 | my $raw_http_body = ''; | |||||||||||||||||||||||||||
| 196 | 0 | ▶ | if( $content_length > 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 197 | 0 | my $raw_http_body = ''; | |||||||||||||||||||||||||||
| 198 | 0 | read( $client, $raw_http_body, $content_length ); | |||||||||||||||||||||||||||
| 199 | 0 | chomp( $raw_http_body ); | |||||||||||||||||||||||||||
| 200 | 0 | $globals->user_post( $raw_http_body ); | |||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | 0 | return( $raw_http_headers, $raw_http_body ); # for debugging | |||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | # _uri_unescape( STRING ) | ||||||||||||||||||||||||||||
| 207 | # This private method takes a string in the argument STRING, and returns | ||||||||||||||||||||||||||||
| 208 | # an uri-unescaped version of it. | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | 0 | ▶ | sub _uri_unescape { | ||||||||||||||||||||||||||
|
Subroutine
_uri_unescape: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 211 | 0 | my ($self, $str) = @_; | |||||||||||||||||||||||||||
| 212 | 0 | $str =~ tr/+/ /; | |||||||||||||||||||||||||||
| 213 | 0 | $str =~ s/%([0-9a-fA-F]{2})/pack("c",hex($1))/ge; | |||||||||||||||||||||||||||
| 214 | 0 | return( $str ); | |||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | ###################################################################### | ||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | =head2 send_user_output( GLOBALS, CLIENT ) | ||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | This method takes a CGI::Portable object as its first argument, GLOBALS, and | ||||||||||||||||||||||||||||
| 222 | sends to the user as much of the HTTP response and user output details that it | ||||||||||||||||||||||||||||
| 223 | can get from the object. | ||||||||||||||||||||||||||||
| 224 | The second argument, CLIENT, is an IO::Socket::INET object which is the client | ||||||||||||||||||||||||||||
| 225 | we will be sending our output to. | ||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | =head2 send_quick_html_response( CONTENT, CLIENT ) | ||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | This method takes a string containing an HTML document as its first argument, | ||||||||||||||||||||||||||||
| 230 | CONTENT, and sends an http response appropriate for an HTML document which | ||||||||||||||||||||||||||||
| 231 | includes CONTENT as the http body. | ||||||||||||||||||||||||||||
| 232 | The second argument, CLIENT, is an IO::Socket::INET object which is the client | ||||||||||||||||||||||||||||
| 233 | we will be sending our output to. | ||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | =head2 send_quick_redirect_response( URL, CLIENT ) | ||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | This method takes a string containing an url as its first argument, URL, and | ||||||||||||||||||||||||||||
| 238 | sends an http redirection header to send the client browser to that url. | ||||||||||||||||||||||||||||
| 239 | The second argument, CLIENT, is an IO::Socket::INET object which is the client | ||||||||||||||||||||||||||||
| 240 | we will be sending our output to. | ||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | =cut | ||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | ###################################################################### | ||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | 0 | ▶ | sub send_user_output { | ||||||||||||||||||||||||||
|
Subroutine
send_user_output: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 247 | 0 | my ($self, $globals, $client) = @_; | |||||||||||||||||||||||||||
| 248 | 0 | ▶ | my $status = $globals->http_status_code() || '200 OK'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$globals->http_status_code || '200 OK'
MC/DC0%0/1
$globals->http_status_code || '200 OK'
$globals->http_status_code
Truth table0%0/2
A
A= $globals->http_status_code
| |||||||||||||||||||||||||||||
| 249 | 0 | my $target = $globals->http_window_target(); | |||||||||||||||||||||||||||
| 250 | 0 | ▶ | my $type = $globals->http_content_type() || 'text/html'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$globals->http_content_type || 'text/html'
MC/DC0%0/1
$globals->http_content_type || 'text/html'
$globals->http_content_type
Truth table0%0/2
A
A= $globals->http_content_type
| |||||||||||||||||||||||||||||
| 251 | 0 | my $url = $globals->http_redirect_url(); | |||||||||||||||||||||||||||
| 252 | 0 | my @cookies = $globals->get_http_cookies(); | |||||||||||||||||||||||||||
| 253 | 0 | my %misc = $globals->get_http_headers(); | |||||||||||||||||||||||||||
| 254 | 0 | ▶ | my $content = $globals->http_body() || $globals->page_as_string(); | ||||||||||||||||||||||||||
|
Condition0%0/3
$globals->http_body || $globals->page_as_string
MC/DC0%0/2
$globals->http_body || $globals->page_as_string
$globals->http_body
$globals->page_as_string
Truth table0%0/3
A || B
A= $globals->http_bodyB= $globals->page_as_string
| |||||||||||||||||||||||||||||
| 255 | 0 | my $binary = $globals->http_body_is_binary(); | |||||||||||||||||||||||||||
| 256 | 0 | $self->_send_output( $client, $status, $type, $url, $target, $content, | |||||||||||||||||||||||||||
| 257 | $binary, \@cookies, \%misc ); | ||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | 0 | ▶ | sub send_quick_html_response { | ||||||||||||||||||||||||||
|
Subroutine
send_quick_html_response: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 261 | 0 | my ($self, $content, $client) = @_; | |||||||||||||||||||||||||||
| 262 | 0 | $self->_send_output( $client, '200 OK', 'text/html', undef, undef, $content ); | |||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||
| 265 | 0 | ▶ | sub send_quick_redirect_response { | ||||||||||||||||||||||||||
|
Subroutine
send_quick_redirect_response: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 266 | 0 | my ($self, $url, $client) = @_; | |||||||||||||||||||||||||||
| 267 | 0 | $self->_send_output( $client, '301 Moved', undef, $url ); | |||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | # _send_output( CLIENT, STATUS, TYPE, [URL, [TARGET[, CONTENT[, IS_BINARY[, | ||||||||||||||||||||||||||||
| 271 | # COOKIES[, MISC]]]]]] ) | ||||||||||||||||||||||||||||
| 272 | # This private method is used to implement all the send_*() methods above, | ||||||||||||||||||||||||||||
| 273 | # and works under both mod_perl and cgi. It currently does not support NPH | ||||||||||||||||||||||||||||
| 274 | # responses but that should be added in the future. | ||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||
| 276 | 0 | ▶ | sub _send_output { | ||||||||||||||||||||||||||
|
Subroutine
_send_output: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||
| 277 | 0 | my ($self, $client, $status, $type, $url, $target, $content, $is_binary, | |||||||||||||||||||||||||||
| 278 | $cook, $misc) = @_; | ||||||||||||||||||||||||||||
| 279 | 0 | ▶ | ref($cook) eq 'ARRAY' or $cook = []; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 280 | 0 | ▶ | ref($misc) eq 'HASH' or $misc = {}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||
| 282 | 0 | my @header = ("Status: $status"); | |||||||||||||||||||||||||||
| 283 | 0 | ▶ | $target and push( @header, "Window-Target: $target" ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 284 | 0 | ▶ | @{$cook} and push( @header, map { "Set-Cookie: $_" } @{$cook} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 285 | 0 | ▶ | push( @header, $url ? "Location: $url" : "Content-Type: $type" ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 286 | 0 | ▶ | %{$misc} and push( @header, map { "$_: $misc->{$_}" } sort keys %{$misc} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 287 | 0 | unshift( @header, "HTTP/1.0 $status" ); | |||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||
| 289 | 0 | my $endl = "\015\012"; # cr + lf | |||||||||||||||||||||||||||
| 290 | 0 | my $header = join( $endl, @header ).$endl.$endl; | |||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||
| 292 | 0 | $client->autoflush(1); | |||||||||||||||||||||||||||
| 293 | 0 | print $client $header; | |||||||||||||||||||||||||||
| 294 | 0 | ▶ | $is_binary and binmode( $client ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 295 | 0 | print $client $content; | |||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||
| 298 | ###################################################################### | ||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||
| 300 | 1 | 1; | |||||||||||||||||||||||||||
| 301 | __END__ | ||||||||||||||||||||||||||||