File tree Expand file tree Collapse file tree 8 files changed +69
-26
lines changed
lib/Apache2/Filter/Minifier Expand file tree Collapse file tree 8 files changed +69
-26
lines changed Original file line number Diff line number Diff line change 1
1
Revision history for Perl extension Apache2::Filter::Minifier::JavaScript.
2
2
3
+ 1.04_02 ???
4
+ - decline processing if unable to determine Content-Type of document
5
+
3
6
1.04_01 Tue Oct 16 00:59 PDT 2007
4
7
- added timing info to the debug logs
5
8
- use JavaScript::Minifier::XS if available; its -MUCH- faster
Original file line number Diff line number Diff line change @@ -6,8 +6,8 @@ MANIFEST.SKIP
6
6
META.yml
7
7
README.txt
8
8
lib/Apache2/Filter/Minifier/JavaScript.pm
9
- t/charset.t
10
9
t/content-length.t
10
+ t/content-type.t
11
11
t/decline.t
12
12
t/dynamic.t
13
13
t/mime-types.t
@@ -25,6 +25,7 @@ t/htdocs/minified-xs.txt
25
25
t/MY/slurp.pm
26
26
t/MY/CharsetHandler.pm
27
27
t/MY/JSHandler.pm
28
+ t/MY/NoCTypeHandler.pm
28
29
t/MY/PlainHandler.pm
29
30
t/MY/UpperCase.pm
30
31
t/perl-bin/js.pl
Original file line number Diff line number Diff line change 1
1
---
2
2
name : Apache2-Filter-Minifier-JavaScript
3
- version : 1.04_01
3
+ version : 1.04_02
4
4
author :
5
5
-
Graham TerMarsch ([email protected] )
6
6
abstract : JS minifying output filter
@@ -18,7 +18,7 @@ recommends:
18
18
provides :
19
19
Apache2::Filter::Minifier::JavaScript :
20
20
file : lib/Apache2/Filter/Minifier/JavaScript.pm
21
- version : 1.04_01
21
+ version : 1.04_02
22
22
generated_by : Module::Build version 0.2805
23
23
meta-spec :
24
24
url : http://module-build.sourceforge.net/META-spec-v1.2.html
Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ eval { require JavaScript::Minifier::XS; };
19
19
20
20
# ##############################################################################
21
21
# Version number.
22
- our $VERSION = ' 1.04_01 ' ;
22
+ our $VERSION = ' 1.04_02 ' ;
23
23
24
24
# ##############################################################################
25
25
# MIME-Types we're willing to minify.
@@ -47,8 +47,11 @@ sub handler {
47
47
);
48
48
49
49
# determine Content-Type of document
50
- my $ctype = $r -> content_type;
51
- $ctype =~ s { ;.*} {} ;
50
+ my ($ctype ) = ($r -> content_type =~ / ^(.+?)(?:;.*)?$ / );
51
+ unless ($ctype ) {
52
+ $log -> info( " unable to determine content type; skipping : URL " , $r -> uri );
53
+ return Apache2::Const::DECLINED;
54
+ }
52
55
53
56
# only process JS documents
54
57
unless (exists $types {$ctype }) {
Original file line number Diff line number Diff line change
1
+ package MY::NoCTypeHandler ;
2
+
3
+ use strict;
4
+ use warnings;
5
+ use Apache2::RequestIO qw( ) ;
6
+ use Apache2::RequestRec qw( ) ;
7
+ use Apache2::RequestUtil qw( ) ;
8
+ use Apache2::Const -compile => qw( OK) ;
9
+ use File::Spec::Functions qw( catfile) ;
10
+ use MY::slurp;
11
+
12
+ sub handler {
13
+ my $r = shift ;
14
+ $r -> print ( slurp(catfile($r -> document_root,' test.txt' )) );
15
+ return Apache2::Const::OK;
16
+ }
17
+
18
+ 1;
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -27,12 +27,18 @@ Alias /raw @DocumentRoot@
27
27
PerlAddVar JsMimeType text/json
28
28
</Location>
29
29
30
- <Location /charset>
30
+ <Location /content-type/ charset>
31
31
SetHandler modperl
32
32
PerlResponseHandler MY::CharsetHandler
33
33
PerlOutputFilterHandler Apache2::Filter::Minifier::JavaScript
34
34
</Location>
35
35
36
+ <Location /content-type/missing>
37
+ SetHandler modperl
38
+ PerlResponseHandler MY::NoCTypeHandler
39
+ PerlOutputFilterHandler Apache2::Filter::Minifier::JavaScript
40
+ </Location>
41
+
36
42
<Location /decline_uc>
37
43
SetHandler modperl
38
44
PerlResponseHandler MY::PlainHandler
Original file line number Diff line number Diff line change
1
+ use strict;
2
+ use warnings FATAL => ' all' ;
3
+ use Apache::Test;
4
+ use Apache::TestRequest;
5
+ use Apache::TestUtil qw( t_cmp) ;
6
+ use lib ' t' ;
7
+ use MY::slurp;
8
+
9
+ # Test "Content-Type" headers
10
+ plan tests => 3, need_lwp;
11
+
12
+ # "Content-Type" with additional attributes (e.g. "charset")
13
+ charset_minified: {
14
+ my $body = GET_BODY ' /content-type/charset' ;
15
+ my $min = slurp( ' t/htdocs/minified.txt' );
16
+ chomp ($min );
17
+
18
+ ok( t_cmp($body , $min ) );
19
+ }
20
+
21
+ # Missing "Content-Type" header; should decline processing and we get the
22
+ # un-minified version. Apache, however, -will- set a default "Content-Type"
23
+ # into the response.
24
+ content_type_missing: {
25
+ my $res = GET ' /content-type/missing' ;
26
+ my $body = $res -> content;
27
+ my $orig = slurp( ' t/htdocs/test.js' );
28
+
29
+ ok( $res -> content_type !~ m { text/javascript} );
30
+ ok( t_cmp($body , $orig ) );
31
+ }
You can’t perform that action at this time.
0 commit comments