Skip to content

Commit 999ee0d

Browse files
committed
Tests: If-Range tests with proxy.
This covers the following cases: - slice filter and If-Range requests (ticket #1357); - If-Range requests with proxy_force_ranges;
1 parent 462a2a8 commit 999ee0d

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

proxy_force_ranges.t

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use Test::Nginx;
2323
select STDERR; $| = 1;
2424
select STDOUT; $| = 1;
2525

26-
my $t = Test::Nginx->new()->has(qw/http proxy cache/)->plan(4)
26+
my $t = Test::Nginx->new()->has(qw/http proxy cache/)->plan(6)
2727
->write_file_expand('nginx.conf', <<'EOF');
2828
2929
%%TEST_GLOBALS%%
@@ -47,6 +47,11 @@ http {
4747
proxy_pass http://127.0.0.1:8081;
4848
}
4949
50+
location /proxy/ {
51+
proxy_pass http://127.0.0.1:8081/;
52+
proxy_force_ranges on;
53+
}
54+
5055
location /cache/ {
5156
proxy_pass http://127.0.0.1:8081/;
5257
proxy_cache NAME;
@@ -62,6 +67,8 @@ http {
6267
6368
location / {
6469
max_ranges 0;
70+
add_header Last-Modified "Mon, 28 Sep 1970 06:00:00 GMT";
71+
add_header ETag '"59a5401c-8"';
6572
}
6673
}
6774
}
@@ -85,6 +92,23 @@ like(http_get_range('/cache/t.html', 'Range: bytes=4-'), qr/^THIS/m,
8592
like(http_get_range('/cache/t.html', 'Range: bytes=0-2,4-'), qr/^SEE.*^THIS/ms,
8693
'cached multipart range');
8794

95+
# If-Range HTTP-date request
96+
97+
TODO: {
98+
local $TODO = 'not yet' unless $t->has_version('1.13.5');
99+
100+
like(http_get_range('/proxy/t.html',
101+
"Range: bytes=4-\nIf-Range: Mon, 28 Sep 1970 06:00:00 GMT"),
102+
qr/^THIS/m, 'if-range last-modified proxy');
103+
104+
}
105+
106+
# If-Range entity-tag request
107+
108+
like(http_get_range('/proxy/t.html',
109+
"Range: bytes=4-\nIf-Range: \"59a5401c-8\""),
110+
qr/^THIS/m, 'if-range etag proxy');
111+
88112
###############################################################################
89113

90114
sub http_get_range {

slice.t

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ select STDERR; $| = 1;
2323
select STDOUT; $| = 1;
2424

2525
my $t = Test::Nginx->new()->has(qw/http proxy cache fastcgi slice rewrite/)
26-
->plan(74);
26+
->plan(76);
2727

2828
$t->write_file_expand('nginx.conf', <<'EOF');
2929
@@ -50,6 +50,14 @@ http {
5050
5151
location / { }
5252
53+
location /proxy/ {
54+
slice 2;
55+
56+
proxy_pass http://127.0.0.1:8081/;
57+
58+
proxy_set_header Range $slice_range;
59+
}
60+
5361
location /cache/ {
5462
slice 2;
5563
@@ -223,6 +231,18 @@ $r = get('/cache/t?if', "Range: bytes=3-4\nIf-Range: $etag");
223231
like($r, qr/ 206 /, 'if-range - 206 partial reply');
224232
like($r, qr/^34$/m, 'if-range - correct content');
225233

234+
# respect Last-Modified from non-cacheable response with If-Range
235+
236+
TODO: {
237+
local $TODO = 'not yet' unless $t->has_version('1.13.5');
238+
239+
my ($lm) = http_get('/t') =~ /Last-Modified: (.*)/;
240+
$r = get('/proxy/t', "Range: bytes=3-4\nIf-Range: $lm");
241+
like($r, qr/ 206 /, 'if-range last-modified proxy - 206 partial reply');
242+
like($r, qr/^34$/m, 'if-range last-modified proxy - correct content');
243+
244+
}
245+
226246
$r = get('/cache/t?ifb', "Range: bytes=3-4\nIf-Range: bad");
227247
like($r, qr/ 200 /, 'if-range bad - 200 ok');
228248
like($r, qr/^0123456789abcdef$/m, 'if-range bad - correct content');

0 commit comments

Comments
 (0)