Maxim Dounin | b5a4f2b | 2009-03-25 14:12:33 +0300 | [diff] [blame] | 1 | #!/usr/bin/perl |
| 2 | |
| 3 | # (C) Maxim Dounin |
| 4 | |
| 5 | # Tests for http proxy cache. |
| 6 | |
| 7 | ############################################################################### |
| 8 | |
| 9 | use warnings; |
| 10 | use strict; |
| 11 | |
Maxim Dounin | 8d0eed2 | 2009-04-06 04:48:51 +0400 | [diff] [blame] | 12 | use Test::More tests => 5; |
Maxim Dounin | b5a4f2b | 2009-03-25 14:12:33 +0300 | [diff] [blame] | 13 | |
| 14 | BEGIN { use FindBin; chdir($FindBin::Bin); } |
| 15 | |
| 16 | use lib 'lib'; |
| 17 | use Test::Nginx; |
| 18 | |
| 19 | ############################################################################### |
| 20 | |
| 21 | select STDERR; $| = 1; |
| 22 | select STDOUT; $| = 1; |
| 23 | |
| 24 | my $t = Test::Nginx->new(); |
| 25 | |
| 26 | $t->write_file_expand('nginx.conf', <<'EOF'); |
| 27 | |
| 28 | master_process off; |
| 29 | daemon off; |
| 30 | |
| 31 | events { |
| 32 | } |
| 33 | |
| 34 | http { |
| 35 | access_log off; |
| 36 | root %%TESTDIR%%; |
| 37 | |
| 38 | client_body_temp_path %%TESTDIR%%/client_body_temp; |
| 39 | fastcgi_temp_path %%TESTDIR%%/fastcgi_temp; |
| 40 | proxy_temp_path %%TESTDIR%%/proxy_temp; |
| 41 | |
| 42 | proxy_cache_path %%TESTDIR%%/cache levels=1:2 |
Maxim Dounin | 8d0eed2 | 2009-04-06 04:48:51 +0400 | [diff] [blame] | 43 | keys_zone=NAME:10m; |
Maxim Dounin | b5a4f2b | 2009-03-25 14:12:33 +0300 | [diff] [blame] | 44 | |
| 45 | server { |
| 46 | listen 127.0.0.1:8080; |
| 47 | server_name localhost; |
| 48 | |
| 49 | location / { |
| 50 | proxy_pass http://127.0.0.1:8081; |
| 51 | |
| 52 | proxy_cache NAME; |
| 53 | |
| 54 | proxy_cache_valid 200 302 1h; |
| 55 | proxy_cache_valid 301 1d; |
| 56 | proxy_cache_valid any 1m; |
| 57 | |
| 58 | proxy_cache_min_uses 1; |
| 59 | |
| 60 | proxy_cache_use_stale error timeout invalid_header http_500; |
| 61 | } |
| 62 | } |
| 63 | server { |
| 64 | listen 127.0.0.1:8081; |
| 65 | server_name localhost; |
| 66 | |
| 67 | location / { |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | EOF |
| 73 | |
| 74 | $t->write_file('t.html', 'SEE-THIS'); |
Maxim Dounin | 8d0eed2 | 2009-04-06 04:48:51 +0400 | [diff] [blame] | 75 | $t->write_file('t2.html', 'SEE-THIS'); |
Maxim Dounin | b5a4f2b | 2009-03-25 14:12:33 +0300 | [diff] [blame] | 76 | $t->run(); |
| 77 | |
| 78 | ############################################################################### |
| 79 | |
| 80 | like(http_get('/t.html'), qr/SEE-THIS/, 'proxy request'); |
| 81 | |
| 82 | $t->write_file('t.html', 'NOOP'); |
| 83 | like(http_get('/t.html'), qr/SEE-THIS/, 'proxy request cached'); |
| 84 | |
Maxim Dounin | 8d0eed2 | 2009-04-06 04:48:51 +0400 | [diff] [blame] | 85 | unlike(http_head('/t2.html'), qr/SEE-THIS/, 'head request'); |
| 86 | like(http_get('/t2.html'), qr/SEE-THIS/, 'get after head'); |
| 87 | unlike(http_head('/t2.html'), qr/SEE-THIS/, 'head after get'); |
| 88 | |
Maxim Dounin | b5a4f2b | 2009-03-25 14:12:33 +0300 | [diff] [blame] | 89 | ############################################################################### |