[nginx] svn commit: r4975 - trunk/src/http/modules

ru at nginx.com ru at nginx.com
Wed Dec 19 10:30:45 UTC 2012


Author: ru
Date: 2012-12-19 10:30:45 +0000 (Wed, 19 Dec 2012)
New Revision: 4975
URL: http://trac.nginx.org/nginx/changeset/4975/nginx

Log:
Slightly optimized code that handles special headers in "add_header".


Modified:
   trunk/src/http/modules/ngx_http_headers_filter_module.c

Modified: trunk/src/http/modules/ngx_http_headers_filter_module.c
===================================================================
--- trunk/src/http/modules/ngx_http_headers_filter_module.c	2012-12-18 18:39:39 UTC (rev 4974)
+++ trunk/src/http/modules/ngx_http_headers_filter_module.c	2012-12-19 10:30:45 UTC (rev 4975)
@@ -74,7 +74,9 @@
 
     { ngx_string("Cache-Control"), 0, ngx_http_add_cache_control },
 
-    { ngx_string("Last-Modified"), 0, ngx_http_set_last_modified },
+    { ngx_string("Last-Modified"),
+                 offsetof(ngx_http_headers_out_t, last_modified),
+                 ngx_http_set_last_modified },
 
     { ngx_string("ETag"),
                  offsetof(ngx_http_headers_out_t, etag),
@@ -372,28 +374,13 @@
 ngx_http_set_last_modified(ngx_http_request_t *r, ngx_http_header_val_t *hv,
     ngx_str_t *value)
 {
-    ngx_table_elt_t  *h;
-
-    ngx_http_clear_last_modified(r);
-
-    if (value->len == 0) {
-        return NGX_OK;
-    }
-
-    r->headers_out.last_modified_time = ngx_http_parse_time(value->data,
-                                                            value->len);
-
-    h = ngx_list_push(&r->headers_out.headers);
-    if (h == NULL) {
+    if (ngx_http_set_response_header(r, hv, value) != NGX_OK) {
         return NGX_ERROR;
     }
 
-    r->headers_out.last_modified = h;
+    r->headers_out.last_modified_time =
+        (value->len) ? ngx_http_parse_time(value->data, value->len) : -1;
 
-    h->hash = 1;
-    h->key = hv->key;
-    h->value = *value;
-
     return NGX_OK;
 }
 
@@ -406,22 +393,27 @@
 
     old = (ngx_table_elt_t **) ((char *) &r->headers_out + hv->offset);
 
-    if (*old) {
-        (*old)->hash = 0;
-        *old = NULL;
-    }
+    if (value->len == 0) {
+        if (*old) {
+            (*old)->hash = 0;
+            *old = NULL;
+        }
 
-    if (value->len == 0) {
         return NGX_OK;
     }
 
-    h = ngx_list_push(&r->headers_out.headers);
-    if (h == NULL) {
-        return NGX_ERROR;
+    if (*old) {
+        h = *old;
+
+    } else {
+        h = ngx_list_push(&r->headers_out.headers);
+        if (h == NULL) {
+            return NGX_ERROR;
+        }
+
+        *old = h;
     }
 
-    *old = h;
-
     h->hash = 1;
     h->key = hv->key;
     h->value = *value;



More information about the nginx-devel mailing list