line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#--------------------------------------------------------------------- |
2
|
|
|
|
|
|
|
package Apache2::HttpEquiv; |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# Copyright 2012 Christopher J. Madsen |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# Author: Christopher J. Madsen |
7
|
|
|
|
|
|
|
# Created: 11 Mar 2006 |
8
|
|
|
|
|
|
|
# |
9
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or modify |
10
|
|
|
|
|
|
|
# it under the same terms as Perl itself. |
11
|
|
|
|
|
|
|
# |
12
|
|
|
|
|
|
|
# This program is distributed in the hope that it will be useful, |
13
|
|
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either the |
15
|
|
|
|
|
|
|
# GNU General Public License or the Artistic License for more details. |
16
|
|
|
|
|
|
|
# |
17
|
|
|
|
|
|
|
# ABSTRACT: Convert to HTTP headers |
18
|
|
|
|
|
|
|
#--------------------------------------------------------------------- |
19
|
|
|
|
|
|
|
|
20
|
1
|
|
|
1
|
|
38106
|
use 5.008; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
67
|
|
21
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
49
|
|
22
|
1
|
|
|
1
|
|
699
|
use Apache2::Const -compile => qw(OK DECLINED); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
use HTML::PullParser; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
#===================================================================== |
26
|
|
|
|
|
|
|
# Package Global Variables: |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
our $VERSION = '1.00'; |
29
|
|
|
|
|
|
|
# This file is part of Apache2-HttpEquiv 1.00 (January 4, 2014) |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
#===================================================================== |
32
|
|
|
|
|
|
|
sub handler |
33
|
|
|
|
|
|
|
{ |
34
|
|
|
|
|
|
|
my $r = shift; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
return Apache2::Const::DECLINED |
37
|
|
|
|
|
|
|
unless $r->is_initial_req |
38
|
|
|
|
|
|
|
and $r->content_type eq "text/html" |
39
|
|
|
|
|
|
|
and open(my $file, '<:encoding(latin1)', $r->filename); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
my ($p, $token, $header) = HTML::PullParser->new( |
42
|
|
|
|
|
|
|
file => $file, |
43
|
|
|
|
|
|
|
start => 'tag, attr', |
44
|
|
|
|
|
|
|
end => 'tag', |
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
my $content_type; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
while ($token = $p->get_token) { |
50
|
|
|
|
|
|
|
if ($token->[0] eq 'meta') { |
51
|
|
|
|
|
|
|
if ($header = $token->[1]{'charset'} and not defined $content_type) { |
52
|
|
|
|
|
|
|
$content_type = "text/html; charset=$header"; |
53
|
|
|
|
|
|
|
} # end if |
54
|
|
|
|
|
|
|
elsif ($header = $token->[1]{'http-equiv'}) { |
55
|
|
|
|
|
|
|
if ($header eq 'Content-Type' and not defined $content_type) { |
56
|
|
|
|
|
|
|
$content_type = $token->[1]{content}; |
57
|
|
|
|
|
|
|
# text/xhtml is not a valid content type: |
58
|
|
|
|
|
|
|
$content_type =~ s!^text/xhtml(?=\s|;|\z)!text/html!i; |
59
|
|
|
|
|
|
|
} else { |
60
|
|
|
|
|
|
|
$r->headers_out->set($header => $token->[1]{content}); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
} # end elsif |
63
|
|
|
|
|
|
|
} # end if tag |
64
|
|
|
|
|
|
|
last if $token->[0] eq 'body' or $token->[0] eq '/head'; |
65
|
|
|
|
|
|
|
} # end while get_token |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
$r->content_type($content_type) if $content_type; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
close($file); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
return Apache2::Const::OK; |
72
|
|
|
|
|
|
|
} # end handler |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
#===================================================================== |
75
|
|
|
|
|
|
|
# Package Return Value: |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
__END__ |