mod-compress.t 3.3 KB

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