changeset 1211:0c15ba7d19b3

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;
author Sergey Kandaurov <pluknet@nginx.com>
date Tue, 29 Aug 2017 16:56:52 +0300
parents 3ca5b0081bc6
children 0469ef3fcd34
files proxy_force_ranges.t slice.t
diffstat 2 files changed, 46 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/proxy_force_ranges.t
+++ b/proxy_force_ranges.t
@@ -23,7 +23,7 @@ use Test::Nginx;
 select STDERR; $| = 1;
 select STDOUT; $| = 1;
 
-my $t = Test::Nginx->new()->has(qw/http proxy cache/)->plan(4)
+my $t = Test::Nginx->new()->has(qw/http proxy cache/)->plan(6)
 	->write_file_expand('nginx.conf', <<'EOF');
 
 %%TEST_GLOBALS%%
@@ -47,6 +47,11 @@ http {
             proxy_pass    http://127.0.0.1:8081;
         }
 
+        location /proxy/ {
+            proxy_pass    http://127.0.0.1:8081/;
+            proxy_force_ranges on;
+        }
+
         location /cache/ {
             proxy_pass    http://127.0.0.1:8081/;
             proxy_cache   NAME;
@@ -62,6 +67,8 @@ http {
 
         location / {
             max_ranges 0;
+            add_header Last-Modified "Mon, 28 Sep 1970 06:00:00 GMT";
+            add_header ETag '"59a5401c-8"';
         }
     }
 }
@@ -85,6 +92,23 @@ like(http_get_range('/cache/t.html', 'Ra
 like(http_get_range('/cache/t.html', 'Range: bytes=0-2,4-'), qr/^SEE.*^THIS/ms,
 	'cached multipart range');
 
+# If-Range HTTP-date request
+
+TODO: {
+local $TODO = 'not yet' unless $t->has_version('1.13.5');
+
+like(http_get_range('/proxy/t.html',
+	"Range: bytes=4-\nIf-Range: Mon, 28 Sep 1970 06:00:00 GMT"),
+	qr/^THIS/m, 'if-range last-modified proxy');
+
+}
+
+# If-Range entity-tag request
+
+like(http_get_range('/proxy/t.html',
+	"Range: bytes=4-\nIf-Range: \"59a5401c-8\""),
+	qr/^THIS/m, 'if-range etag proxy');
+
 ###############################################################################
 
 sub http_get_range {
--- a/slice.t
+++ b/slice.t
@@ -23,7 +23,7 @@ select STDERR; $| = 1;
 select STDOUT; $| = 1;
 
 my $t = Test::Nginx->new()->has(qw/http proxy cache fastcgi slice rewrite/)
-	->plan(74);
+	->plan(76);
 
 $t->write_file_expand('nginx.conf', <<'EOF');
 
@@ -50,6 +50,14 @@ http {
 
         location / { }
 
+        location /proxy/ {
+            slice 2;
+
+            proxy_pass    http://127.0.0.1:8081/;
+
+            proxy_set_header   Range  $slice_range;
+        }
+
         location /cache/ {
             slice 2;
 
@@ -223,6 +231,18 @@ like(get('/cache/t?im', "If-Match: bad")
 like($r, qr/ 206 /, 'if-range - 206 partial reply');
 like($r, qr/^34$/m, 'if-range - correct content');
 
+# respect Last-Modified from non-cacheable response with If-Range
+
+TODO: {
+local $TODO = 'not yet' unless $t->has_version('1.13.5');
+
+my ($lm) = http_get('/t') =~ /Last-Modified: (.*)/;
+$r = get('/proxy/t', "Range: bytes=3-4\nIf-Range: $lm");
+like($r, qr/ 206 /, 'if-range last-modified proxy - 206 partial reply');
+like($r, qr/^34$/m, 'if-range last-modified proxy - correct content');
+
+}
+
 $r = get('/cache/t?ifb', "Range: bytes=3-4\nIf-Range: bad");
 like($r, qr/ 200 /, 'if-range bad - 200 ok');
 like($r, qr/^0123456789abcdef$/m, 'if-range bad - correct content');