line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Plack::Middleware::Headers; |
2
|
|
|
|
|
|
|
#ABSTRACT: modify HTTP response headers |
3
|
|
|
|
|
|
|
|
4
|
5
|
|
|
5
|
|
24112
|
use strict; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
184
|
|
5
|
5
|
|
|
5
|
|
137
|
use 5.008_001; |
|
5
|
|
|
|
|
16
|
|
|
5
|
|
|
|
|
188
|
|
6
|
5
|
|
|
5
|
|
749
|
use parent qw(Plack::Middleware); |
|
5
|
|
|
|
|
271
|
|
|
5
|
|
|
|
|
38
|
|
7
|
5
|
|
|
5
|
|
16385
|
use Plack::Util::Accessor qw(set append unset code when); |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
68
|
|
8
|
|
|
|
|
|
|
|
9
|
5
|
|
|
5
|
|
363
|
use Plack::Util; |
|
5
|
|
|
|
|
14
|
|
|
5
|
|
|
|
|
122
|
|
10
|
5
|
|
|
5
|
|
23
|
use Scalar::Util qw(reftype); |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
2760
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.11'; #VERSION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub prepare_app { |
15
|
16
|
|
|
16
|
1
|
6925
|
my $self = shift; |
16
|
|
|
|
|
|
|
|
17
|
16
|
100
|
100
|
|
|
42
|
if (ref $self->when and ref $self->when eq 'ARRAY') { |
18
|
4
|
|
|
|
|
191
|
my @when = @{$self->when}; |
|
4
|
|
|
|
|
12
|
|
19
|
|
|
|
|
|
|
$self->when( sub { |
20
|
8
|
|
|
8
|
|
86
|
my @headers = @_; |
21
|
8
|
|
|
|
|
11
|
my $match = 0; |
22
|
8
|
|
|
|
|
21
|
for (my $i = 0; $i < @when; $i += 2) { |
23
|
18
|
|
|
|
|
35
|
my ($key, $check) = ($when[ $i ], $when[ $i + 1 ]); |
24
|
|
|
|
|
|
|
|
25
|
18
|
|
|
|
|
44
|
my $value = Plack::Util::header_get(\@headers, $key); |
26
|
|
|
|
|
|
|
|
27
|
18
|
100
|
|
|
|
339
|
if (!defined $check) { # missing header check |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
28
|
4
|
100
|
|
|
|
15
|
next if defined $value; |
29
|
|
|
|
|
|
|
} elsif( !defined $value ) { # header missing |
30
|
4
|
|
|
|
|
12
|
next; |
31
|
|
|
|
|
|
|
} elsif( ref $check ) { # regex match header |
32
|
6
|
100
|
|
|
|
41
|
next if $value !~ $check; |
33
|
|
|
|
|
|
|
} elsif ( $value ne $check ) { # exact header |
34
|
2
|
|
|
|
|
5
|
next; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
6
|
|
|
|
|
29
|
return 1; |
38
|
|
|
|
|
|
|
} |
39
|
2
|
|
|
|
|
9
|
return; |
40
|
4
|
|
|
|
|
41
|
}); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub call { |
45
|
32
|
|
|
32
|
1
|
106861
|
my $self = shift; |
46
|
32
|
|
|
|
|
136
|
my $res = $self->app->(@_); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
$self->response_cb( |
49
|
|
|
|
|
|
|
$res, |
50
|
|
|
|
|
|
|
sub { |
51
|
32
|
|
|
32
|
|
539
|
my $res = shift; |
52
|
|
|
|
|
|
|
|
53
|
32
|
100
|
100
|
|
|
90
|
if ($self->code and $self->code ne $res->[0]) { |
54
|
1
|
|
|
|
|
16
|
return; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
31
|
|
|
|
|
221
|
my $headers = $res->[1]; |
58
|
|
|
|
|
|
|
|
59
|
31
|
100
|
100
|
|
|
79
|
if ($self->when and !$self->when->(@$headers)) { |
60
|
4
|
|
|
|
|
99
|
return; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
27
|
100
|
|
|
|
389
|
if ( $self->set ) { |
64
|
21
|
|
|
|
|
282
|
Plack::Util::header_iter( |
65
|
|
|
|
|
|
|
$self->set, sub {Plack::Util::header_set($headers, @_)} |
66
|
21
|
|
|
|
|
149
|
); |
67
|
|
|
|
|
|
|
} |
68
|
27
|
100
|
|
|
|
627
|
if ( $self->append ) { |
69
|
4
|
|
|
|
|
20
|
push @$headers, @{$self->append}; |
|
4
|
|
|
|
|
12
|
|
70
|
|
|
|
|
|
|
} |
71
|
27
|
100
|
|
|
|
261
|
if ( $self->unset ) { |
72
|
2
|
|
|
|
|
14
|
Plack::Util::header_remove($headers, $_) for @{$self->unset}; |
|
2
|
|
|
|
|
8
|
|
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} |
75
|
32
|
|
|
|
|
563
|
); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
__END__ |