Mercurial > hg > nginx-tests
comparison proxy_cache_max_range_offset.t @ 1078:36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Thu, 03 Nov 2016 13:20:20 +0300 |
parents | |
children | 766bcbb632ee |
comparison
equal
deleted
inserted
replaced
1077:13247bbc1f7d | 1078:36437be7b3f4 |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 # (C) Sergey Kandaurov | |
4 # (C) Nginx, Inc. | |
5 | |
6 # Tests for http proxy cache, proxy_cache_max_range_offset directive. | |
7 | |
8 ############################################################################### | |
9 | |
10 use warnings; | |
11 use strict; | |
12 | |
13 use Test::More; | |
14 | |
15 BEGIN { use FindBin; chdir($FindBin::Bin); } | |
16 | |
17 use lib 'lib'; | |
18 use Test::Nginx; | |
19 | |
20 ############################################################################### | |
21 | |
22 select STDERR; $| = 1; | |
23 select STDOUT; $| = 1; | |
24 | |
25 my $t = Test::Nginx->new()->has(qw/http proxy cache/) | |
26 ->write_file_expand('nginx.conf', <<'EOF'); | |
27 | |
28 %%TEST_GLOBALS%% | |
29 | |
30 daemon off; | |
31 | |
32 events { | |
33 } | |
34 | |
35 http { | |
36 %%TEST_GLOBALS_HTTP%% | |
37 | |
38 proxy_cache_path %%TESTDIR%%/cache levels=1:2 | |
39 keys_zone=NAME:1m; | |
40 | |
41 server { | |
42 listen 127.0.0.1:8080; | |
43 server_name localhost; | |
44 | |
45 location / { | |
46 proxy_pass http://127.0.0.1:8081/; | |
47 proxy_cache NAME; | |
48 proxy_cache_valid 200 1m; | |
49 proxy_cache_max_range_offset 2; | |
50 } | |
51 | |
52 location /zero/ { | |
53 proxy_pass http://127.0.0.1:8081/; | |
54 proxy_cache NAME; | |
55 proxy_cache_valid 200 1m; | |
56 proxy_cache_max_range_offset 0; | |
57 } | |
58 | |
59 location /min_uses/ { | |
60 proxy_pass http://127.0.0.1:8081/; | |
61 proxy_cache NAME; | |
62 proxy_cache_valid 200 1m; | |
63 proxy_cache_max_range_offset 2; | |
64 proxy_cache_min_uses 2; | |
65 } | |
66 } | |
67 | |
68 server { | |
69 listen 127.0.0.1:8081; | |
70 server_name localhost; | |
71 | |
72 location / { | |
73 add_header X-Range $http_range; | |
74 } | |
75 } | |
76 } | |
77 | |
78 EOF | |
79 | |
80 $t->write_file('t.html', 'SEE-THIS'); | |
81 $t->try_run('no proxy_cache_max_range_offset')->plan(8); | |
82 | |
83 ############################################################################### | |
84 | |
85 unlike(get('/t.html?1', 'bytes=1-'), qr/X-Range/, 'range - below'); | |
86 like(get('/t.html?2', 'bytes=3-'), qr/X-Range/, 'range - above'); | |
87 like(get('/t.html?3', 'bytes=-1'), qr/X-Range/, 'range - last'); | |
88 | |
89 TODO: { | |
90 local $TODO = 'not yet'; | |
91 | |
92 like(get('/t.html?4', 'bytes=1-1,3-'), qr/X-Range/, 'range - multipart above'); | |
93 | |
94 } | |
95 | |
96 like(get('/zero/t.html?5', 'bytes=0-0'), qr/X-Range/, 'always non-cacheable'); | |
97 like(get('/min_uses/t.html?6', 'bytes=1-'), qr/X-Range/, 'below min_uses'); | |
98 | |
99 # no range in client request | |
100 | |
101 like(http_get('/t.html'), qr/SEE-THIS/, 'no range'); | |
102 | |
103 $t->write_file('t.html', 'NOOP'); | |
104 like(http_get('/t.html'), qr/SEE-THIS/, 'no range - cached'); | |
105 | |
106 ############################################################################### | |
107 | |
108 sub get { | |
109 my ($url, $extra) = @_; | |
110 return http(<<EOF); | |
111 GET $url HTTP/1.1 | |
112 Host: localhost | |
113 Connection: close | |
114 Range: $extra | |
115 | |
116 EOF | |
117 } | |
118 | |
119 ############################################################################### |