perl_gzip.t 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #!/usr/bin/perl
  2. # (C) Maxim Dounin
  3. # Tests for embedded perl module.
  4. ###############################################################################
  5. use warnings;
  6. use strict;
  7. use Test::More;
  8. BEGIN { use FindBin; chdir($FindBin::Bin); }
  9. use lib 'lib';
  10. use Test::Nginx qw/ :DEFAULT :gzip /;
  11. ###############################################################################
  12. select STDERR; $| = 1;
  13. select STDOUT; $| = 1;
  14. eval { require IO::Compress::Gzip; };
  15. Test::More::plan(skip_all => "IO::Compress::Gzip not found") if $@;
  16. my $t = Test::Nginx->new()->has(qw/http perl gzip/)->plan(2)
  17. ->write_file_expand('nginx.conf', <<'EOF');
  18. %%TEST_GLOBALS%%
  19. master_process off;
  20. daemon off;
  21. events {
  22. }
  23. http {
  24. %%TEST_GLOBALS_HTTP%%
  25. server {
  26. listen 127.0.0.1:8080;
  27. server_name localhost;
  28. gzip on;
  29. gzip_types text/plain;
  30. location / {
  31. perl 'sub {
  32. my $r = shift;
  33. $r->send_http_header("text/plain");
  34. return OK if $r->header_only;
  35. $r->print("TEST");
  36. return OK;
  37. }';
  38. }
  39. location /gz {
  40. perl 'sub {
  41. my $r = shift;
  42. $r->header_out("Content-Encoding", "gzip");
  43. $r->send_http_header("text/plain");
  44. return OK if $r->header_only;
  45. use IO::Compress::Gzip;
  46. my $in = "TEST";
  47. my $out;
  48. IO::Compress::Gzip::gzip(\\$in => \\$out);
  49. $r->print($out);
  50. return OK;
  51. }';
  52. }
  53. }
  54. }
  55. EOF
  56. $t->run();
  57. ###############################################################################
  58. http_gzip_like(http_gzip_request('/'), qr/TEST/, 'perl response gzipped');
  59. TODO: {
  60. local $TODO = 'patch pending';
  61. http_gzip_like(http_gzip_request('/gz'), qr/TEST/, 'not doublegzipped');
  62. }
  63. ###############################################################################