comparison proxy_force_ranges.t @ 472:c8e790dcbe19

Tests: proxy_force_ranges tests.
author Sergey Kandaurov <pluknet@nginx.com>
date Tue, 14 Oct 2014 18:54:36 +0400
parents
children 907e89fba9c3
comparison
equal deleted inserted replaced
471:8816a0edfc7b 472:c8e790dcbe19
1 #!/usr/bin/perl
2
3 # (C) Sergey Kandaurov
4 # (C) Nginx, Inc.
5
6 # Tests for http proxy cache and range filter.
7 # proxy_force_ranges enables partial response regardless Accept-Ranges.
8
9 ###############################################################################
10
11 use warnings;
12 use strict;
13
14 use Test::More;
15
16 BEGIN { use FindBin; chdir($FindBin::Bin); }
17
18 use lib 'lib';
19 use Test::Nginx;
20
21 ###############################################################################
22
23 select STDERR; $| = 1;
24 select STDOUT; $| = 1;
25
26 plan(skip_all => 'win32') if $^O eq 'MSWin32';
27
28 my $t = Test::Nginx->new()->has(qw/http proxy cache/)
29 ->write_file_expand('nginx.conf', <<'EOF');
30
31 %%TEST_GLOBALS%%
32
33 daemon off;
34
35 events {
36 }
37
38 http {
39 %%TEST_GLOBALS_HTTP%%
40
41 proxy_cache_path %%TESTDIR%%/cache levels=1:2
42 keys_zone=NAME:1m;
43
44 server {
45 listen 127.0.0.1:8080;
46 server_name localhost;
47
48 location / {
49 proxy_pass http://127.0.0.1:8081;
50 }
51
52 location /cache/ {
53 proxy_pass http://127.0.0.1:8081/;
54 proxy_cache NAME;
55 proxy_cache_valid 200 1m;
56
57 proxy_force_ranges on;
58 }
59 }
60
61 server {
62 listen 127.0.0.1:8081;
63 server_name localhost;
64
65 location / {
66 max_ranges 0;
67 }
68 }
69 }
70
71 EOF
72
73 $t->write_file('t.html', 'SEE-THIS');
74 $t->try_run('no proxy_force_ranges')->plan(5);
75
76 ###############################################################################
77
78 # serving range requests requires Accept-Ranges by default
79
80 unlike(http_get_range('/t.html', 'Range: bytes=4-'), qr/^THIS/m,
81 'range without Accept-Ranges');
82
83 like(http_get_range('/cache/t.html', 'Range: bytes=4-'), qr/^THIS/m,
84 'uncached range');
85 like(http_get_range('/cache/t.html', 'Range: bytes=4-'), qr/^THIS/m,
86 'cached range');
87 like(http_get_range('/cache/t.html', 'Range: bytes=0-2,4-'), qr/^SEE.*^THIS/ms,
88 'cached multipart range');
89
90 like(`grep -F '[alert]' ${\($t->testdir())}/error.log`, qr/^$/s, 'no alerts');
91
92 ###############################################################################
93
94 sub http_get_range {
95 my ($url, $extra) = @_;
96 return http(<<EOF);
97 GET $url HTTP/1.1
98 Host: localhost
99 Connection: close
100 $extra
101
102 EOF
103 }
104
105 ###############################################################################