]> git.kaiwu.me - nginx.git/commitdiff
merge r3137, r3198, r3199, r3353, r3370, r3371, r3398, r3399:
authorIgor Sysoev <igor@sysoev.ru>
Mon, 1 Feb 2010 15:46:14 +0000 (15:46 +0000)
committerIgor Sysoev <igor@sysoev.ru>
Mon, 1 Feb 2010 15:46:14 +0000 (15:46 +0000)
cache related fixes:

*) do not pass buf with empty cached response,
   this fixes "zero size buf in output" alert
*) hide cacheable Set-Cookie and P3P FastCGI response headers
*) test comma separator in "Cache-Control"
*) a cache manager thread handle was overwritten by a cache loader thread
   handle, this caused an exit delay, the bug had been introduced in r3248
*) fix handling cached HTTP/0.9 response
*) log proxied HTTP/0.9 responses status as "009"
*) fix the "If-None-Match" header name
*) fix a cached zero-length body case

src/http/modules/ngx_http_fastcgi_module.c
src/http/modules/ngx_http_log_module.c
src/http/modules/ngx_http_proxy_module.c
src/http/ngx_http_file_cache.c
src/http/ngx_http_upstream.c
src/os/win32/ngx_process_cycle.c

index bdc52b644cbcaed5aa121fe38778f865a13ac55f..a4a62e4cc48a8decdf426c200dac440a4f135fad 100644 (file)
@@ -523,6 +523,23 @@ static ngx_str_t  ngx_http_fastcgi_hide_headers[] = {
 };
 
 
+#if (NGX_HTTP_CACHE)
+
+static ngx_str_t  ngx_http_fastcgi_hide_cache_headers[] = {
+    ngx_string("Status"),
+    ngx_string("X-Accel-Expires"),
+    ngx_string("X-Accel-Redirect"),
+    ngx_string("X-Accel-Limit-Rate"),
+    ngx_string("X-Accel-Buffering"),
+    ngx_string("X-Accel-Charset"),
+    ngx_string("Set-Cookie"),
+    ngx_string("P3P"),
+    ngx_null_string
+};
+
+#endif
+
+
 static ngx_path_init_t  ngx_http_fastcgi_temp_path = {
     ngx_string(NGX_HTTP_FASTCGI_TEMP_PATH), { 1, 2, 0 }
 };
@@ -1899,6 +1916,7 @@ ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
     u_char                       *p;
     size_t                        size;
     uintptr_t                    *code;
+    ngx_str_t                    *h;
     ngx_uint_t                    i;
     ngx_keyval_t                 *src;
     ngx_hash_init_t               hash;
@@ -2119,10 +2137,18 @@ ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
     hash.bucket_size = ngx_align(64, ngx_cacheline_size);
     hash.name = "fastcgi_hide_headers_hash";
 
+#if (NGX_HTTP_CACHE)
+
+    h = conf->upstream.cache ? ngx_http_fastcgi_hide_cache_headers:
+                               ngx_http_fastcgi_hide_headers;
+#else
+
+    h = ngx_http_fastcgi_hide_headers;
+
+#endif
+
     if (ngx_http_upstream_hide_headers_hash(cf, &conf->upstream,
-                                            &prev->upstream,
-                                            ngx_http_fastcgi_hide_headers,
-                                            &hash)
+                                            &prev->upstream, h, &hash)
         != NGX_OK)
     {
         return NGX_CONF_ERROR;
index e1d99c05a50de62da3bf91e494c649eaf6ce4230..515203889edcc0774b79ffe0a1521651f8ba84ce 100644 (file)
@@ -542,8 +542,25 @@ ngx_http_log_request_time(ngx_http_request_t *r, u_char *buf,
 static u_char *
 ngx_http_log_status(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op)
 {
-    return ngx_sprintf(buf, "%ui",
-                       r->err_status ? r->err_status : r->headers_out.status);
+    ngx_uint_t  status;
+
+    if (r->err_status) {
+        status = r->err_status;
+
+    } else if (r->headers_out.status) {
+        status = r->headers_out.status;
+
+    } else if (r->http_version == NGX_HTTP_VERSION_9) {
+        *buf++ = '0';
+        *buf++ = '0';
+        *buf++ = '9';
+        return buf;
+
+    } else {
+        status = 0;
+    }
+
+    return ngx_sprintf(buf, "%ui", status);
 }
 
 
index 9da8b4c55f35f976a37bf6ff9d3313f20f2c2ed0..19dbd5cfcf73f3719249786cf539a8d2e3810607 100644 (file)
@@ -530,7 +530,7 @@ static ngx_keyval_t  ngx_http_proxy_cache_headers[] = {
     { ngx_string("Expect"), ngx_string("") },
     { ngx_string("If-Modified-Since"), ngx_string("") },
     { ngx_string("If-Unmodified-Since"), ngx_string("") },
-    { ngx_string("If-Match-None"), ngx_string("") },
+    { ngx_string("If-None-Match"), ngx_string("") },
     { ngx_string("If-Match"), ngx_string("") },
     { ngx_string("Range"), ngx_string("") },
     { ngx_string("If-Range"), ngx_string("") },
@@ -1223,7 +1223,6 @@ ngx_http_proxy_process_status_line(ngx_http_request_t *r)
 
         if (r->cache) {
             r->http_version = NGX_HTTP_VERSION_9;
-            u->headers_in.status_n = NGX_HTTP_OK;
             return NGX_OK;
         }
 
@@ -1239,7 +1238,6 @@ ngx_http_proxy_process_status_line(ngx_http_request_t *r)
 #endif
 
         r->http_version = NGX_HTTP_VERSION_9;
-        u->headers_in.status_n = NGX_HTTP_OK;
         u->state->status = NGX_HTTP_OK;
 
         return NGX_OK;
index a60483d598b4dc7dc26a459a839c118dc0f78bee..c02bc77405e67fb419747dd0f358529c844b8e34 100644 (file)
@@ -311,7 +311,7 @@ ngx_http_file_cache_open(ngx_http_request_t *r)
         return n;
     }
 
-    if ((size_t) n <= c->header_start) {
+    if ((size_t) n < c->header_start) {
         ngx_log_error(NGX_LOG_CRIT, r->connection->log, 0,
                       "cache file \"%s\" is too small", c->file.name.data);
         return NGX_ERROR;
@@ -718,6 +718,8 @@ ngx_http_cache_send(ngx_http_request_t *r)
         return NGX_HTTP_INTERNAL_SERVER_ERROR;
     }
 
+    r->header_only = (c->length - c->body_start) == 0;
+
     rc = ngx_http_send_header(r);
 
     if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) {
@@ -727,7 +729,7 @@ ngx_http_cache_send(ngx_http_request_t *r)
     b->file_pos = c->body_start;
     b->file_last = c->length;
 
-    b->in_file = (c->length - c->body_start) ? 1: 0;
+    b->in_file = 1;
     b->last_buf = (r == r->main) ? 1: 0;
     b->last_in_chain = 1;
 
index 943ef69e8b15ec223eb559b0b149fff73f50ece8..2deec48193fe050392299fab971edbed9fe12b4c 100644 (file)
@@ -712,6 +712,11 @@ ngx_http_upstream_cache_send(ngx_http_request_t *r, ngx_http_upstream_t *u)
     r->cached = 1;
     c = r->cache;
 
+    if (c->header_start == c->body_start) {
+        r->http_version = NGX_HTTP_VERSION_9;
+        return ngx_http_cache_send(r);
+    }
+
     /* TODO: cache stack */
 
     u->buffer = *c->buf;
@@ -3017,7 +3022,7 @@ ngx_http_upstream_process_cache_control(ngx_http_request_t *r,
     n = 0;
 
     for (p += 8; p < last; p++) {
-        if (*p == ';' || *p == ' ') {
+        if (*p == ',' || *p == ';' || *p == ' ') {
             break;
         }
 
index 59016b961009bf303d16bb0187f3a8ee2fb1e8a8..e3b513a1c1c5752b795748fb2ecc385f5f039bde 100644 (file)
@@ -599,7 +599,7 @@ ngx_worker_process_cycle(ngx_cycle_t *cycle, char *mevn)
     HANDLE      mev, events[3];
     u_long      nev, ev;
     ngx_err_t   err;
-    ngx_tid_t   wtid, cmtid;
+    ngx_tid_t   wtid, cmtid, cltid;
     ngx_log_t  *log;
 
     log = cycle->log;
@@ -671,7 +671,7 @@ ngx_worker_process_cycle(ngx_cycle_t *cycle, char *mevn)
         goto failed;
     }
 
-    if (ngx_create_thread(&cmtid, ngx_cache_loader_thread, NULL, log) != 0) {
+    if (ngx_create_thread(&cltid, ngx_cache_loader_thread, NULL, log) != 0) {
         goto failed;
     }