proxy_xar.t 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/usr/bin/perl
  2. # (C) Maxim Dounin
  3. # Tests for proxy X-Accel-Redirect functionality.
  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;
  11. ###############################################################################
  12. select STDERR; $| = 1;
  13. select STDOUT; $| = 1;
  14. my $t = Test::Nginx->new()->has(qw/http proxy rewrite/)->plan(8);
  15. $t->write_file_expand('nginx.conf', <<'EOF');
  16. %%TEST_GLOBALS%%
  17. master_process off;
  18. daemon off;
  19. events {
  20. }
  21. http {
  22. %%TEST_GLOBALS_HTTP%%
  23. server {
  24. listen 127.0.0.1:8080;
  25. server_name localhost;
  26. location /proxy {
  27. proxy_pass http://127.0.0.1:8080/return-xar;
  28. }
  29. location /return-xar {
  30. add_header X-Accel-Redirect /index.html;
  31. # this headers will be preserved on
  32. # X-Accel-Redirect
  33. add_header Content-Type text/blah;
  34. add_header Set-Cookie blah=blah;
  35. add_header Content-Disposition attachment;
  36. add_header Cache-Control no-cache;
  37. add_header Expires fake;
  38. add_header Accept-Ranges parrots;
  39. # others won't be
  40. add_header Something other;
  41. return 204;
  42. }
  43. }
  44. }
  45. EOF
  46. $t->write_file('index.html', 'SEE-THIS');
  47. $t->run();
  48. ###############################################################################
  49. my $r = http_get('/proxy');
  50. like($r, qr/SEE-THIS/, 'X-Accel-Redirect works');
  51. like($r, qr/^Content-Type: text\/blah/m, 'Content-Type preserved');
  52. like($r, qr/^Set-Cookie: blah=blah/m, 'Set-Cookie preserved');
  53. like($r, qr/^Content-Disposition: attachment/m, 'Content-Disposition preserved');
  54. like($r, qr/^Cache-Control: no-cache/m, 'Cache-Control preserved');
  55. like($r, qr/^Expires: fake/m, 'Expires preserved');
  56. like($r, qr/^Accept-Ranges: parrots/m, 'Accept-Ranges preserved');
  57. unlike($r, qr/^Something/m, 'other headers stripped');
  58. ###############################################################################