Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#1357 closed defect (fixed)

slice+if_range problem

Reported by: cjhust@… Owned by:
Priority: minor Milestone:
Component: other Version: 1.12.x
Keywords: Cc:
uname -a:
Linux localhost.localdomain 3.10.0-327.22.2.el7.x86_64 #1
nginx -V: nginx version: nginx/1.11.2

Description (last modified by Maxim Dounin)

server {
    listen 8888;

    location / {
        root html;
    }
}


server {
    listen 8000;

    location / {
        slice 128K;
        proxy_set_header range $slice_range;
        proxy_pass http://127.0.0.1:8888/;
    }
}


server {
    listen 8001;

    location / {
        proxy_pass http://127.0.0.1:8888/;
    }
}
#curl http://127.0.0.1:8001/4K.mp4 -o /dev/null -v -H 'range: bytes=1-2' -H 'if-range: Wed, 09 Aug 2017 08:29:34 GMT'
* About to connect() to 127.0.0.1 port 8001 (#0)
*   Trying 127.0.0.1...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0* Connected to 127.0.0.1 (127.0.0.1) port 8001 (#0)
> GET /4K.mp4 HTTP/1.1
> User-Agent: curl/7.29.0
> Host: 127.0.0.1:8001
> Accept: */*
> range: bytes=1-2
> if-range: Wed, 09 Aug 2017 08:29:34 GMT
> 
< HTTP/1.1 206 Partial Content
< Server: nginx/1.11.2
< Date: Tue, 15 Aug 2017 03:54:28 GMT
< Content-Type: video/mp4
< Content-Length: 2
< Connection: keep-alive
< Last-Modified: Wed, 09 Aug 2017 08:29:34 GMT
< ETag: "598ac7ee-1000"
< Content-Range: bytes 1-2/4096
< 
{ [data not shown]
100     2  100     2    0     0   1010      0 --:--:-- --:--:-- --:--:--  2000
* Connection #0 to host 127.0.0.1 left intact

return 206, meet expectation



#curl http://127.0.0.1:8000/4K.mp4 -o /dev/null -v -H 'range: bytes=1-2' -H 'if-range: Wed, 09 Aug 2017 08:29:34 GMT' 
* About to connect() to 127.0.0.1 port 8000 (#0)
*   Trying 127.0.0.1...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0* Connected to 127.0.0.1 (127.0.0.1) port 8000 (#0)
> GET /4K.mp4 HTTP/1.1
> User-Agent: curl/7.29.0
> Host: 127.0.0.1:8000
> Accept: */*
> range: bytes=1-2
> if-range: Wed, 09 Aug 2017 08:29:34 GMT
> 
< HTTP/1.1 200 OK
< Server: nginx/1.11.2
< Date: Tue, 15 Aug 2017 03:54:46 GMT
< Content-Type: video/mp4
< Content-Length: 4096
< Connection: keep-alive
< Last-Modified: Wed, 09 Aug 2017 08:29:34 GMT
< ETag: "598ac7ee-1000"
< Accept-Ranges: bytes
< 
{ [data not shown]
100  4096  100  4096    0     0  1036k      0 --:--:-- --:--:-- --:--:-- 1333k
* Connection #0 to host 127.0.0.1 left intact

return 200, not meet expectation

Is there some reason for slice module?
for user viewport, slice and no slice method must not change the HTTP result.

Change History (6)

comment:1 by cjhust@…, 7 years ago

The If-Range HTTP request header makes a range request conditional: if the condition is fulfilled, the range request will be issued and the server sends back a 206 Partial Content answer with the appropriate body. If the condition is not fulfilled, the full resource is sent back, with a 200 OK status.

comment:2 by Maxim Dounin, 7 years ago

Description: modified (diff)

Please try the following patch:

# HG changeset patch
# User Maxim Dounin <mdounin@mdounin.ru>
# Date 1502813238 -10800
#      Tue Aug 15 19:07:18 2017 +0300
# Node ID d51ee844db963d4c51ea1d9eed335af19c95f43a
# Parent  a2f5e25d6a283546f76435b9fc3e7e814b092bae
Upstream: unconditional parsing of last_modified_time.

This fixes at least the following cases, where no last_modified_time
(assuming caching is not enabled) resulted in incorrect behaviour:

- slice filter and If-Range requests (ticket #1357);
- If-Range requests with proxy_force_ranges;
- expires modified.

diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c
--- a/src/http/ngx_http_upstream.c
+++ b/src/http/ngx_http_upstream.c
@@ -4390,15 +4390,8 @@ ngx_http_upstream_process_last_modified(
     u = r->upstream;
 
     u->headers_in.last_modified = h;
-
-#if (NGX_HTTP_CACHE)
-
-    if (u->cacheable) {
-        u->headers_in.last_modified_time = ngx_parse_http_time(h->value.data,
-                                                               h->value.len);
-    }
-
-#endif
+    u->headers_in.last_modified_time = ngx_parse_http_time(h->value.data,
+                                                           h->value.len);
 
     return NGX_OK;
 }
@@ -4940,15 +4933,8 @@ ngx_http_upstream_copy_last_modified(ngx
     *ho = *h;
 
     r->headers_out.last_modified = ho;
-
-#if (NGX_HTTP_CACHE)
-
-    if (r->upstream->cacheable) {
-        r->headers_out.last_modified_time =
+    r->headers_out.last_modified_time =
                                     r->upstream->headers_in.last_modified_time;
-    }
-
-#endif
 
     return NGX_OK;
 }

comment:3 by cjhust@…, 7 years ago

OK, thank you

comment:4 by Maxim Dounin <mdounin@…>, 7 years ago

In 7093:acc2cddc7b45/nginx:

Upstream: unconditional parsing of last_modified_time.

This fixes at least the following cases, where no last_modified_time
(assuming caching is not enabled) resulted in incorrect behaviour:

  • slice filter and If-Range requests (ticket #1357);
  • If-Range requests with proxy_force_ranges;
  • expires modified.

comment:5 by Maxim Dounin, 7 years ago

Resolution: fixed
Status: newclosed

Patch committed, thanks for reporting this.

comment:6 by Sergey Kandaurov <pluknet@…>, 7 years ago

In 1211:0c15ba7d19b3/nginx-tests:

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;
Note: See TracTickets for help on using tickets.