changeset 4742:3cb5cf1e1439

Added Last-Modified parsing in add_header. This allows to use last modified time set in If-Range checks. Code simplified to improve readability.
author Maxim Dounin <mdounin@mdounin.ru>
date Sat, 07 Jul 2012 21:16:51 +0000
parents 5ea8c710c532
children 84cc73e01aa8
files src/http/modules/ngx_http_headers_filter_module.c
diffstat 1 files changed, 13 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/src/http/modules/ngx_http_headers_filter_module.c
+++ b/src/http/modules/ngx_http_headers_filter_module.c
@@ -72,9 +72,7 @@ static ngx_http_set_header_t  ngx_http_s
 
     { ngx_string("Cache-Control"), 0, ngx_http_add_cache_control },
 
-    { ngx_string("Last-Modified"),
-                 offsetof(ngx_http_headers_out_t, last_modified),
-                 ngx_http_set_last_modified },
+    { ngx_string("Last-Modified"), 0, ngx_http_set_last_modified },
 
     { ngx_null_string, 0, NULL }
 };
@@ -368,33 +366,23 @@ static ngx_int_t
 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, **old;
+    ngx_table_elt_t  *h;
 
-    old = (ngx_table_elt_t **) ((char *) &r->headers_out + hv->offset);
-
-    r->headers_out.last_modified_time = -1;
+    ngx_http_clear_last_modified(r);
 
-    if (*old == NULL) {
-
-        if (value->len == 0) {
-            return NGX_OK;
-        }
+    if (value->len == 0) {
+        return NGX_OK;
+    }
 
-        h = ngx_list_push(&r->headers_out.headers);
-        if (h == NULL) {
-            return NGX_ERROR;
-        }
-
-        *old = h;
+    r->headers_out.last_modified_time = ngx_http_parse_time(value->data,
+                                                            value->len);
 
-    } else {
-        h = *old;
+    h = ngx_list_push(&r->headers_out.headers);
+    if (h == NULL) {
+        return NGX_ERROR;
+    }
 
-        if (value->len == 0) {
-            h->hash = 0;
-            return NGX_OK;
-        }
-    }
+    r->headers_out.last_modified = h;
 
     h->hash = 1;
     h->key = hv->key;