line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CGI::Easy::Headers; |
2
|
2
|
|
|
2
|
|
1355
|
use 5.010001; |
|
2
|
|
|
|
|
6
|
|
3
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
39
|
|
4
|
2
|
|
|
2
|
|
8
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
30
|
|
5
|
2
|
|
|
2
|
|
7
|
use utf8; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
7
|
|
6
|
2
|
|
|
2
|
|
44
|
use Carp; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
125
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = 'v2.0.1'; |
9
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
9
|
use CGI::Easy::Util qw( date_http make_cookie ); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
8
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
11
|
|
|
11
|
1
|
59
|
my ($class, $opt) = @_; |
15
|
|
|
|
|
|
|
my $self = { |
16
|
|
|
|
|
|
|
'Status' => '200 OK', |
17
|
|
|
|
|
|
|
'Content-Type' => 'text/html; charset=utf-8', |
18
|
|
|
|
|
|
|
'Date' => q{}, |
19
|
|
|
|
|
|
|
'Set-Cookie' => [], |
20
|
11
|
50
|
|
|
|
37
|
$opt ? %{$opt} : (), |
|
0
|
|
|
|
|
0
|
|
21
|
|
|
|
|
|
|
}; |
22
|
11
|
|
|
|
|
23
|
return bless $self, $class; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub add_cookie { |
26
|
11
|
|
|
11
|
1
|
263
|
my ($self, @cookies) = @_; |
27
|
11
|
|
|
|
|
12
|
push @{ $self->{'Set-Cookie'} }, @cookies; |
|
11
|
|
|
|
|
26
|
|
28
|
11
|
|
|
|
|
20
|
return; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub redirect { |
32
|
1
|
|
|
1
|
1
|
5
|
my ($self, $url, $status) = @_; |
33
|
1
|
|
|
|
|
2
|
$self->{'Location'} = $url; |
34
|
1
|
50
|
|
|
|
3
|
if (!defined $status) { |
35
|
1
|
|
|
|
|
14
|
$status = '302 Found'; |
36
|
|
|
|
|
|
|
} |
37
|
1
|
|
|
|
|
2
|
$self->{'Status'} = $status; |
38
|
1
|
|
|
|
|
2
|
return; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub require_basic_auth { |
42
|
0
|
|
|
0
|
1
|
0
|
my ($self, $realm) = @_; |
43
|
0
|
0
|
|
|
|
0
|
if (!defined $realm) { |
44
|
0
|
|
|
|
|
0
|
$realm = q{}; |
45
|
|
|
|
|
|
|
} |
46
|
0
|
|
|
|
|
0
|
$self->{'WWW-Authenticate'} = "Basic realm=\"$realm\""; |
47
|
0
|
|
|
|
|
0
|
$self->{'Status'} = '401 Authorization Required'; |
48
|
0
|
|
|
|
|
0
|
return; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub compose { |
52
|
6
|
|
|
6
|
1
|
502
|
my ($self) = @_; |
53
|
6
|
|
|
|
|
7
|
my %h = %{$self}; |
|
6
|
|
|
|
|
24
|
|
54
|
6
|
|
|
|
|
16
|
for my $header (keys %h) { |
55
|
26
|
|
|
|
|
48
|
my $expect = join q{-}, map {ucfirst lc} split /-/xms, $header; |
|
38
|
|
|
|
|
88
|
|
56
|
26
|
|
|
|
|
45
|
$expect =~ s/\bEtag\b/ETag/xms; |
57
|
26
|
|
|
|
|
29
|
$expect =~ s/\bWww\b/WWW/xms; |
58
|
26
|
|
|
|
|
28
|
$expect =~ s/\bMd5\b/MD5/xms; |
59
|
26
|
50
|
|
|
|
46
|
if ($header ne $expect) { |
60
|
0
|
|
|
|
|
0
|
croak "Bad header name '$header' (should be '$expect')"; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
6
|
|
|
|
|
20
|
my $s = sprintf "Status: %s\r\n", delete $h{'Status'}; |
65
|
6
|
|
|
|
|
13
|
$s .= sprintf "Content-Type: %s\r\n", delete $h{'Content-Type'}; |
66
|
6
|
|
|
|
|
11
|
my $date = delete $h{'Date'}; |
67
|
6
|
50
|
|
|
|
12
|
if (defined $date) { |
68
|
6
|
|
33
|
|
|
21
|
$s .= sprintf "Date: %s\r\n", $date || date_http(time); |
69
|
|
|
|
|
|
|
} |
70
|
6
|
|
|
|
|
9
|
for my $cookie (@{ delete $h{'Set-Cookie'} }) { |
|
6
|
|
|
|
|
12
|
|
71
|
12
|
|
|
|
|
22
|
$s .= make_cookie($cookie); |
72
|
|
|
|
|
|
|
} |
73
|
6
|
|
|
|
|
11
|
for my $header (keys %h) { |
74
|
2
|
50
|
|
|
|
8
|
if (!ref $h{$header}) { |
75
|
2
|
|
|
|
|
4
|
$h{$header} = [ $h{$header} ]; |
76
|
|
|
|
|
|
|
} |
77
|
2
|
|
|
|
|
9
|
for my $value (@{ $h{$header} }) { |
|
2
|
|
|
|
|
6
|
|
78
|
2
|
|
|
|
|
7
|
$s .= sprintf "%s: %s\r\n", $header, $value; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
6
|
|
|
|
|
35
|
return $s . "\r\n"; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
1; # Magic true value required at end of module |
87
|
|
|
|
|
|
|
__END__ |