annotate not_modified_proxy.t @ 568:907e89fba9c3

Tests: removed TODO and try_run() checks for legacy versions.
author Sergey Kandaurov <pluknet@nginx.com>
date Sun, 03 May 2015 12:45:09 +0300
parents f5f2a66853a9
children 2cd00179f4b2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
418
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
1 #!/usr/bin/perl
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
2
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
3 # (C) Maxim Dounin
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
4
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
5 # Tests for not modified filter module and it's interaction with proxy.
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
6 #
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
7 # Notably, requests which are proxied should be skipped (that is, if
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
8 # a backend returned 200, we should pass 200 to a client without any
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
9 # attempts to handle conditional headers in the request), but responses
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
10 # from cache should be handled.
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
11
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
12 ###############################################################################
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
13
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
14 use warnings;
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
15 use strict;
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
16
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
17 use Test::More;
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
18
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
19 BEGIN { use FindBin; chdir($FindBin::Bin); }
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
20
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
21 use lib 'lib';
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
22 use Test::Nginx;
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
23
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
24 ###############################################################################
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
25
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
26 select STDERR; $| = 1;
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
27 select STDOUT; $| = 1;
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
28
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
29 plan(skip_all => 'win32') if $^O eq 'MSWin32';
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
30
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
31 my $t = Test::Nginx->new()->has(qw/http proxy cache/)->plan(9)
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
32 ->write_file_expand('nginx.conf', <<'EOF');
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
33
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
34 %%TEST_GLOBALS%%
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
35
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
36 daemon off;
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
37
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
38 events {
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
39 }
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
40
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
41 http {
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
42 %%TEST_GLOBALS_HTTP%%
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
43
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
44 proxy_cache_path %%TESTDIR%%/cache keys_zone=one:1m;
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
45
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
46 proxy_set_header If-Modified-Since "";
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
47 proxy_set_header If-None-Match "";
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
48
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
49 server {
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
50 listen 127.0.0.1:8080;
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
51 server_name localhost;
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
52
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
53 location / {
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
54 }
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
55
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
56 location /etag {
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
57 add_header Last-Modified "";
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
58 }
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
59
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
60 location /proxy/ {
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
61 proxy_pass http://127.0.0.1:8080/;
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
62 }
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
63
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
64 location /cache/ {
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
65 proxy_pass http://127.0.0.1:8080/;
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
66 proxy_cache one;
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
67 proxy_cache_valid 200 1y;
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
68 }
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
69 }
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
70 }
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
71
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
72 EOF
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
73
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
74 $t->write_file('t', '');
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
75 $t->write_file('etag', '');
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
76
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
77 $t->run();
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
78
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
79 ###############################################################################
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
80
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
81 my ($t1, $lm, $etag);
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
82
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
83 $t1 = http_get('/cache/t');
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
84 $t1 =~ /Last-Modified: (.*)/; $lm = $1;
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
85 $t1 =~ /ETag: (.*)/; $etag = $1;
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
86
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
87 like(http_get_ims('/t', $lm), qr/ 304 /, 'if-modified-since');
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
88 like(http_get_ims('/proxy/t', $lm), qr/ 200 /, 'ims proxy ignored');
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
89 like(http_get_ims('/cache/t', $lm), qr/ 304 /, 'ims from cache');
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
90
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
91 like(http_get_inm('/t', $etag), qr/ 304 /, 'if-none-match');
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
92 like(http_get_inm('/proxy/t', $etag), qr/ 200 /, 'inm proxy ignored');
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
93 like(http_get_inm('/cache/t', $etag), qr/ 304 /, 'inm from cache');
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
94
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
95 # backend response with ETag only, no Last-Modified
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
96
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
97 $t1 = http_get('/cache/etag');
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
98 $t1 =~ /ETag: (.*)/; $etag = $1;
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
99
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
100 like(http_get_inm('/etag', $etag), qr/ 304 /, 'if-none-match etag only');
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
101 like(http_get_inm('/proxy/etag', $etag), qr/ 200 /, 'inm etag proxy ignored');
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
102 like(http_get_inm('/cache/etag', $etag), qr/ 304 /, 'inm etag from cache');
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
103
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
104 ###############################################################################
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
105
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
106 sub http_get_ims {
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
107 my ($url, $ims) = @_;
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
108 return http(<<EOF);
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
109 GET $url HTTP/1.0
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
110 Host: localhost
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
111 If-Modified-Since: $ims
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
112
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
113 EOF
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
114 }
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
115
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
116 sub http_get_inm {
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
117 my ($url, $inm) = @_;
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
118 return http(<<EOF);
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
119 GET $url HTTP/1.0
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
120 Host: localhost
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
121 If-None-Match: $inm
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
122
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
123 EOF
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
124 }
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
125
861e6cad6299 Tests: tests for not modified filter with proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
126 ###############################################################################