1#!/usr/bin/env perl
2BEGIN {
3	# add current source dir to the include-path
4	# we need this for make distcheck
5	(my $srcdir = $0) =~ s,/[^/]+$,/,;
6	unshift @INC, $srcdir;
7}
8
9use strict;
10use IO::Socket;
11use Test::More tests => 11;
12use LightyTest;
13
14my $tf = LightyTest->new();
15my $t;
16
17$tf->{CONFIGFILE} = 'mod-compress.conf';
18
19ok($tf->start_proc == 0, "Starting lighttpd") or die();
20
21$t->{REQUEST}  = ( <<EOF
22GET /index.html HTTP/1.0
23Accept-Encoding: deflate
24EOF
25 );
26$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, '+Vary' => '' } ];
27ok($tf->handle_http($t) == 0, 'Vary is set');
28
29$t->{REQUEST}  = ( <<EOF
30GET /index.html HTTP/1.0
31Accept-Encoding: deflate
32Host: no-cache.example.org
33EOF
34 );
35$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, '+Vary' => '', 'Content-Length' => '1288', '+Content-Encoding' => '' } ];
36ok($tf->handle_http($t) == 0, 'deflate - Content-Length and Content-Encoding is set');
37
38$t->{REQUEST}  = ( <<EOF
39GET /index.html HTTP/1.0
40Accept-Encoding: deflate
41Host: cache.example.org
42EOF
43 );
44$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, '+Vary' => '', 'Content-Length' => '1288', '+Content-Encoding' => '' } ];
45ok($tf->handle_http($t) == 0, 'deflate - Content-Length and Content-Encoding is set');
46
47$t->{REQUEST}  = ( <<EOF
48GET /index.html HTTP/1.0
49Accept-Encoding: gzip
50Host: no-cache.example.org
51EOF
52 );
53$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, '+Vary' => '', 'Content-Length' => '1306', '+Content-Encoding' => '' } ];
54ok($tf->handle_http($t) == 0, 'gzip - Content-Length and Content-Encoding is set');
55
56$t->{REQUEST}  = ( <<EOF
57GET /index.html HTTP/1.0
58Accept-Encoding: gzip
59Host: cache.example.org
60EOF
61 );
62$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, '+Vary' => '', 'Content-Length' => '1306', '+Content-Encoding' => '' } ];
63ok($tf->handle_http($t) == 0, 'gzip - Content-Length and Content-Encoding is set');
64
65
66$t->{REQUEST}  = ( <<EOF
67GET /index.txt HTTP/1.0
68Accept-Encoding: gzip, deflate
69EOF
70 );
71$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, '+Vary' => '', '+Content-Encoding' => '' } ];
72ok($tf->handle_http($t) == 0, 'gzip, deflate - Content-Length and Content-Encoding is set');
73
74$t->{REQUEST}  = ( <<EOF
75GET /index.txt HTTP/1.0
76Accept-Encoding: gzip, deflate
77EOF
78 );
79$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, '+Vary' => '', '+Content-Encoding' => '', 'Content-Type' => "text/plain; charset=utf-8" } ];
80ok($tf->handle_http($t) == 0, 'Content-Type is from the original file');
81
82$t->{REQUEST}  = ( <<EOF
83GET /index.txt HTTP/1.0
84Accept-encoding:
85X-Accept-encoding: x-i2p-gzip;q=1.0, identity;q=0.5, deflate;q=0, gzip;q=0, *;q=0
86User-Agent: MYOB/6.66 (AN/ON)
87Connection: close
88EOF
89 );
90$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, '+Vary' => '', 'Content-Type' => "text/plain; charset=utf-8" } ];
91ok($tf->handle_http($t) == 0, 'Empty Accept-Encoding');
92
93$t->{REQUEST}  = ( <<EOF
94GET /index.txt HTTP/1.0
95Accept-Encoding: bzip2, gzip, deflate
96Host: cache.example.org
97EOF
98 );
99$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, '+Vary' => '', 'Content-Encoding' => 'gzip', 'Content-Type' => "text/plain; charset=utf-8" } ];
100ok($tf->handle_http($t) == 0, 'bzip2 requested but disabled');
101
102
103ok($tf->stop_proc == 0, "Stopping lighttpd");
104