line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Pod::Webserver::Connection; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
15
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
97
|
|
4
|
3
|
|
|
3
|
|
14
|
use warnings; |
|
3
|
|
|
|
|
12
|
|
|
3
|
|
|
|
|
72
|
|
5
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
1712
|
use Pod::Webserver::Request; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
1788
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '3.09'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# ------------------------------------------------ |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub close { |
13
|
5
|
|
|
5
|
0
|
941
|
close $_[0]->{__fh}; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
} # End of close. |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# ------------------------------------------------ |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub get_request { |
20
|
2
|
|
|
2
|
0
|
1336
|
my $self = shift; |
21
|
|
|
|
|
|
|
|
22
|
2
|
|
|
|
|
13
|
my $fh = $self->{__fh}; |
23
|
|
|
|
|
|
|
|
24
|
2
|
|
|
|
|
148
|
my $line = <$fh>; |
25
|
2
|
50
|
33
|
|
|
117
|
if (!defined $line or !($line =~ m!^([A-Z]+)\s+(\S+)\s+HTTP/1\.\d+!)) { |
26
|
0
|
|
|
|
|
0
|
$self->send_error(400); |
27
|
0
|
|
|
|
|
0
|
return; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
2
|
|
|
|
|
44
|
return Pod::Webserver::Request->new(method=>$1, url=>$2); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
} # End of get_request. |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# ------------------------------------------------ |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub new { |
37
|
5
|
|
|
5
|
0
|
3965
|
my ($class, $fh) = @_; |
38
|
|
|
|
|
|
|
|
39
|
5
|
|
|
|
|
87
|
return bless {__fh => $fh}, $class |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
} # End of new. |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# ------------------------------------------------ |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub send_error { |
46
|
1
|
|
|
1
|
0
|
415
|
my ($self, $status_code) = @_; |
47
|
|
|
|
|
|
|
|
48
|
1
|
|
|
|
|
8
|
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
|
|
|
|
|
9
|
$message =~ s/\n/\15\12/gs; |
56
|
|
|
|
|
|
|
|
57
|
1
|
|
|
|
|
3
|
print {$self->{__fh}} $message; |
|
1
|
|
|
|
|
32
|
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
} # End of send_error. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# ------------------------------------------------ |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub send_response { |
64
|
2
|
|
|
2
|
0
|
486
|
my ($self, $response) = @_; |
65
|
|
|
|
|
|
|
|
66
|
2
|
|
|
|
|
16
|
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
|
2
|
|
|
|
|
7
|
while (my ($name, $value) = splice @{$response->{header}}, 0, 2) { |
|
5
|
|
|
|
|
31
|
|
72
|
3
|
|
|
|
|
15
|
$message .= "$name: $value\n"; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
2
|
|
|
|
|
99
|
$message .= "\n$response->{content}"; |
76
|
|
|
|
|
|
|
|
77
|
2
|
|
|
|
|
229
|
$message =~ s/\n/\15\12/gs; |
78
|
|
|
|
|
|
|
|
79
|
2
|
|
|
|
|
6
|
print {$self->{__fh}} $message; |
|
2
|
|
|
|
|
169
|
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
} # End of send_response. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# ------------------------------------------------ |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
1; |