Mercurial > hg > nginx-tests
annotate proxy_force_ranges.t @ 1010:4f739c15069e
Tests: stream $protocol tests.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Fri, 26 Aug 2016 16:28:22 +0300 |
parents | 882267679006 |
children | 196d33c2bb45 |
rev | line source |
---|---|
472
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for http proxy cache and range filter. |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 # proxy_force_ranges enables partial response regardless Accept-Ranges. |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 ############################################################################### |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use warnings; |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 use strict; |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 use Test::More; |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 BEGIN { use FindBin; chdir($FindBin::Bin); } |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use lib 'lib'; |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 use Test::Nginx; |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 ############################################################################### |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 select STDERR; $| = 1; |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 select STDOUT; $| = 1; |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 |
593
6c0a5903d0ae
Tests: cleanup now duplicating tests for no alerts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
574
diff
changeset
|
26 my $t = Test::Nginx->new()->has(qw/http proxy cache shmem/)->plan(4) |
472
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 ->write_file_expand('nginx.conf', <<'EOF'); |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 %%TEST_GLOBALS%% |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 daemon off; |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 events { |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 } |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 http { |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 %%TEST_GLOBALS_HTTP%% |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 proxy_cache_path %%TESTDIR%%/cache levels=1:2 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 keys_zone=NAME:1m; |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
43 listen 127.0.0.1:8080; |
472
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 server_name localhost; |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 location / { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
47 proxy_pass http://127.0.0.1:8081; |
472
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 } |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 location /cache/ { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
51 proxy_pass http://127.0.0.1:8081/; |
472
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 proxy_cache NAME; |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 proxy_cache_valid 200 1m; |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 proxy_force_ranges on; |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 } |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 } |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
60 listen 127.0.0.1:8081; |
472
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 server_name localhost; |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 location / { |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 max_ranges 0; |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 } |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 } |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 } |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 EOF |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 $t->write_file('t.html', 'SEE-THIS'); |
568
907e89fba9c3
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
472
diff
changeset
|
72 $t->run(); |
472
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 ############################################################################### |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 # serving range requests requires Accept-Ranges by default |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 unlike(http_get_range('/t.html', 'Range: bytes=4-'), qr/^THIS/m, |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 'range without Accept-Ranges'); |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 like(http_get_range('/cache/t.html', 'Range: bytes=4-'), qr/^THIS/m, |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 'uncached range'); |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 like(http_get_range('/cache/t.html', 'Range: bytes=4-'), qr/^THIS/m, |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 'cached range'); |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 like(http_get_range('/cache/t.html', 'Range: bytes=0-2,4-'), qr/^SEE.*^THIS/ms, |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 'cached multipart range'); |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 ############################################################################### |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
90 sub http_get_range { |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
91 my ($url, $extra) = @_; |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
92 return http(<<EOF); |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
93 GET $url HTTP/1.1 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
94 Host: localhost |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
95 Connection: close |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
96 $extra |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
97 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
98 EOF |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
99 } |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
100 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
101 ############################################################################### |