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

mdounin at mdounin.ru mdounin at mdounin.ru
Sat Jul 7 21:24:02 UTC 2012


Author: mdounin
Date: 2012-07-07 21:24:01 +0000 (Sat, 07 Jul 2012)
New Revision: 4748
URL: http://trac.nginx.org/nginx/changeset/4748/nginx

Log:
Entity tags: handling in add_header.

Notably this allows to clear ETag if one want to for some reason.


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-07-07 21:22:27 UTC (rev 4747)
+++ trunk/src/http/modules/ngx_http_headers_filter_module.c	2012-07-07 21:24:01 UTC (rev 4748)
@@ -57,6 +57,8 @@
     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,
@@ -74,6 +76,10 @@
 
     { 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 }
 };
 
@@ -392,6 +398,38 @@
 }
 
 
+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);
+
+    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;
+    }
+
+    *old = h;
+
+    h->hash = 1;
+    h->key = hv->key;
+    h->value = *value;
+
+    return NGX_OK;
+}
+
+
 static void *
 ngx_http_headers_create_conf(ngx_conf_t *cf)
 {



More information about the nginx-devel mailing list