patch for Transfer-Encoding: chunked and proxy_cache - check if the file is complete

Anatoli Marinov toli at webforge.bg
Tue Oct 30 13:39:58 UTC 2012


This patch is for 1.2.4. It adds some code that checks if the file is 
complete when Transfer-Encoding: chunked is used.

--- nginx-1.2.4/src/http/modules/ngx_http_proxy_module.c 2012-04-23 
13:40:01.000000000 +0300
+++ nginx-1.2.4_patched/src/http/modules/ngx_http_proxy_module.c 
2012-10-30 14:55:24.106188123 +0200
@@ -1867,7 +1867,7 @@
      return rc;

  done:

+    r->upstream->chunked_cacheable = 1;
      return NGX_DONE;

  invalid:
--- nginx-1.2.4/src/http/ngx_http_upstream.c    2012-08-06 
20:34:08.000000000 +0300
+++ nginx-1.2.4_patched/src/http/ngx_http_upstream.c    2012-10-30 
15:36:23.126381731 +0200
@@ -2687,7 +2687,8 @@

                  tf = u->pipe->temp_file;

-                if (u->headers_in.content_length_n == -1
+                if (((u->headers_in.content_length_n == -1 && 
!u->headers_in.chunked) ||
+                        (u->headers_in.chunked && u->chunked_cacheable))
                      || u->headers_in.content_length_n
                         == tf->offset - (off_t) r->cache->body_start)
                  {
@@ -3442,6 +3443,7 @@
          != NULL)
      {
          r->upstream->headers_in.chunked = 1;
+        r->upstream->chunked_cacheable = 0;
      }

      return NGX_OK;
--- nginx-1.2.4/src/http/ngx_http_upstream.h    2012-02-13 
13:01:58.000000000 +0200
+++ nginx-1.2.4_patched/src/http/ngx_http_upstream.h    2012-10-30 
14:56:36.642547808 +0200
@@ -314,6 +314,8 @@

      unsigned                         store:1;
      unsigned                         cacheable:1;
+    unsigned                         chunked_cacheable:1;
      unsigned                         accel:1;
      unsigned                         ssl:1;
  #if (NGX_HTTP_CACHE)



Best regards
Anatoli Marinov



More information about the nginx-devel mailing list