| 1 | package Pod::Webserver::Connection; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use Pod::Webserver::Request; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 3 | our $VERSION = '3.11'; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | # ------------------------------------------------ | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 3 | ▶ | sub close { | ||||||||||||||||||||||||||
|
Subroutine
close: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 13 | 3 | close $_[0]->{__fh}; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | } # End of close. | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | # ------------------------------------------------ | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 1 | ▶ | sub get_request { | ||||||||||||||||||||||||||
|
Subroutine
get_request: called CC=3 SCAR=13.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 20 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 1 | my $fh = $self->{__fh}; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 1 | my $line = <$fh>; | |||||||||||||||||||||||||||
| 25 | 1 | ▶ | if (!defined $line or !($line =~ m!^([A-Z]+)\s+(\S+)\s+HTTP/1\.\d+!)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $line and $line =~ m[^([A-Z]+)\s+(\S+)\s+HTTP/1\.\d+]
MC/DC0%0/2
defined $line and $line =~ m[^([A-Z]+)\s+(\S+)\s+HTTP/1\.\d+]
defined $line
$line =~ m[^([A-Z]+)\s+(\S+)\s+HTTP/1\.\d+]
Truth table33%1/3
A and B
A= defined $lineB= $line =~ m[^([A-Z]+)\s+(\S+)\s+HTTP/1\.\d+]
| |||||||||||||||||||||||||||||
| 26 | 0 | $self->send_error(400); | |||||||||||||||||||||||||||
| 27 | 0 | return; | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 1 | return Pod::Webserver::Request->new(method=>$1, url=>$2); | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | } # End of get_request. | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | # ------------------------------------------------ | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 3 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 37 | 3 | my ($class, $fh) = @_; | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 3 | return bless {__fh => $fh}, $class | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | } # End of new. | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | # ------------------------------------------------ | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 1 | ▶ | sub send_error { | ||||||||||||||||||||||||||
|
Subroutine
send_error: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 46 | 1 | my ($self, $status_code) = @_; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 1 | my $message = "HTTP/1.0 $status_code HTTP error code $status_code\n" . | |||||||||||||||||||||||||||
| 49 | "Date: " . Pod::Webserver::time2str(time) . "\n" . <<"EOM"; | ||||||||||||||||||||||||||||
| 50 | Content-Type: text/plain | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | Something went wrong, generating code $status_code. | ||||||||||||||||||||||||||||
| 53 | EOM | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 1 | $message =~ s/\n/\15\12/gs; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 1 | print {$self->{__fh}} $message; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | } # End of send_error. | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | # ------------------------------------------------ | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 1 | ▶ | sub send_response { | ||||||||||||||||||||||||||
|
Subroutine
send_response: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 64 | 1 | my ($self, $response) = @_; | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 1 | my $message = "HTTP/1.0 200 OK\n" | |||||||||||||||||||||||||||
| 67 | . "Date: " . Pod::Webserver::time2str(time) . "\n" | ||||||||||||||||||||||||||||
| 68 | . "Content-Type: $response->{content_type}\n"; | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | # This is destructive, but for our local purposes it doesn't matter | ||||||||||||||||||||||||||||
| 71 | 1 | ▶ | while (my ($name, $value) = splice @{$response->{header}}, 0, 2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | 2 | $message .= "$name: $value\n"; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 1 | $message .= "\n$response->{content}"; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 1 | $message =~ s/\n/\15\12/gs; | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 1 | print {$self->{__fh}} $message; | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | } # End of send_response. | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | # ------------------------------------------------ | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 3 | 1; | |||||||||||||||||||||||||||