blob: 0102143fd49f71ab754c3065a246d45831c878e3 [file] [log] [blame]
Maxim Douninb5a4f2b2009-03-25 14:12:33 +03001#!/usr/bin/perl
2
3# (C) Maxim Dounin
4
5# Tests for http proxy cache.
6
7###############################################################################
8
9use warnings;
10use strict;
11
Maxim Dounin8d0eed22009-04-06 04:48:51 +040012use Test::More tests => 5;
Maxim Douninb5a4f2b2009-03-25 14:12:33 +030013
14BEGIN { use FindBin; chdir($FindBin::Bin); }
15
16use lib 'lib';
17use Test::Nginx;
18
19###############################################################################
20
21select STDERR; $| = 1;
22select STDOUT; $| = 1;
23
24my $t = Test::Nginx->new();
25
26$t->write_file_expand('nginx.conf', <<'EOF');
27
28master_process off;
29daemon off;
30
31events {
32}
33
34http {
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 Dounin8d0eed22009-04-06 04:48:51 +040043 keys_zone=NAME:10m;
Maxim Douninb5a4f2b2009-03-25 14:12:33 +030044
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
72EOF
73
74$t->write_file('t.html', 'SEE-THIS');
Maxim Dounin8d0eed22009-04-06 04:48:51 +040075$t->write_file('t2.html', 'SEE-THIS');
Maxim Douninb5a4f2b2009-03-25 14:12:33 +030076$t->run();
77
78###############################################################################
79
80like(http_get('/t.html'), qr/SEE-THIS/, 'proxy request');
81
82$t->write_file('t.html', 'NOOP');
83like(http_get('/t.html'), qr/SEE-THIS/, 'proxy request cached');
84
Maxim Dounin8d0eed22009-04-06 04:48:51 +040085unlike(http_head('/t2.html'), qr/SEE-THIS/, 'head request');
86like(http_get('/t2.html'), qr/SEE-THIS/, 'get after head');
87unlike(http_head('/t2.html'), qr/SEE-THIS/, 'head after get');
88
Maxim Douninb5a4f2b2009-03-25 14:12:33 +030089###############################################################################