diff src/http/modules/ngx_http_headers_filter_module.c @ 680:597573166f34 NGINX_1_3_3

nginx 1.3.3 *) Feature: entity tags support and the "etag" directive. *) Bugfix: trailing dot in a source value was not ignored if the "map" directive was used with the "hostnames" parameter. *) Bugfix: incorrect location might be used to process a request if a URI was changed via a "rewrite" directive before an internal redirect to a named location.
author Igor Sysoev <http://sysoev.ru>
date Tue, 10 Jul 2012 00:00:00 +0400
parents 9fbf3ad94cbf
children 88a1b4797f2e
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
@@ -57,6 +57,8 @@ static ngx_int_t ngx_http_add_header(ngx
     ngx_http_header_val_t *hv, ngx_str_t *value);
 static ngx_int_t ngx_http_set_last_modified(ngx_http_request_t *r,
     ngx_http_header_val_t *hv, ngx_str_t *value);
+static ngx_int_t ngx_http_set_response_header(ngx_http_request_t *r,
+    ngx_http_header_val_t *hv, ngx_str_t *value);
 
 static void *ngx_http_headers_create_conf(ngx_conf_t *cf);
 static char *ngx_http_headers_merge_conf(ngx_conf_t *cf,
@@ -72,9 +74,11 @@ 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_string("ETag"),
+                 offsetof(ngx_http_headers_out_t, etag),
+                 ngx_http_set_response_header },
 
     { ngx_null_string, 0, NULL }
 };
@@ -368,33 +372,55 @@ 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;
+
+    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) {
+        return NGX_ERROR;
+    }
+
+    r->headers_out.last_modified = h;
+
+    h->hash = 1;
+    h->key = hv->key;
+    h->value = *value;
+
+    return NGX_OK;
+}
+
+
+static ngx_int_t
+ngx_http_set_response_header(ngx_http_request_t *r, ngx_http_header_val_t *hv,
+    ngx_str_t *value)
+{
     ngx_table_elt_t  *h, **old;
 
     old = (ngx_table_elt_t **) ((char *) &r->headers_out + hv->offset);
 
-    r->headers_out.last_modified_time = -1;
-
-    if (*old == NULL) {
-
-        if (value->len == 0) {
-            return NGX_OK;
-        }
+    if (*old) {
+        (*old)->hash = 0;
+        *old = NULL;
+    }
 
-        h = ngx_list_push(&r->headers_out.headers);
-        if (h == NULL) {
-            return NGX_ERROR;
-        }
-
-        *old = h;
+    if (value->len == 0) {
+        return NGX_OK;
+    }
 
-    } 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;
-        }
-    }
+    *old = h;
 
     h->hash = 1;
     h->key = hv->key;