comparison not_modified_proxy.t @ 418:861e6cad6299

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