blob: a348d8ce30e17a098c5ce1e623e3de506407df00 [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
12use Test::More tests => 2;
13
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
43 keys_zone=NAME:10m
44 inactive=5m clean_time=2h00m;
45
46 server {
47 listen 127.0.0.1:8080;
48 server_name localhost;
49
50 location / {
51 proxy_pass http://127.0.0.1:8081;
52
53 proxy_cache NAME;
54
55 proxy_cache_valid 200 302 1h;
56 proxy_cache_valid 301 1d;
57 proxy_cache_valid any 1m;
58
59 proxy_cache_min_uses 1;
60
61 proxy_cache_use_stale error timeout invalid_header http_500;
62 }
63 }
64 server {
65 listen 127.0.0.1:8081;
66 server_name localhost;
67
68 location / {
69 }
70 }
71}
72
73EOF
74
75$t->write_file('t.html', 'SEE-THIS');
76$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
85###############################################################################