]> git.kaiwu.me - nginx.git/commitdiff
Entity tags: the "etag" directive.
authorMaxim Dounin <mdounin@mdounin.ru>
Mon, 9 Jul 2012 14:53:42 +0000 (14:53 +0000)
committerMaxim Dounin <mdounin@mdounin.ru>
Mon, 9 Jul 2012 14:53:42 +0000 (14:53 +0000)
It allows to disable generation of nginx's own entity tags, while
still handling ETags in cache properly.  This may be useful e.g.
if one want to serve static files from servers with different ETag
generation algorithms.

src/http/ngx_http_core_module.c
src/http/ngx_http_core_module.h

index ebc9f7413465b97673049e0aa5edcfa2889714e8..a8177aef76677238c10ee35c05934a2e0a6bbfa3 100644 (file)
@@ -650,6 +650,13 @@ static ngx_command_t  ngx_http_core_commands[] = {
       offsetof(ngx_http_core_loc_conf_t, chunked_transfer_encoding),
       NULL },
 
+    { ngx_string("etag"),
+      NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
+      ngx_conf_set_flag_slot,
+      NGX_HTTP_LOC_CONF_OFFSET,
+      offsetof(ngx_http_core_loc_conf_t, etag),
+      NULL },
+
     { ngx_string("error_page"),
       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
                         |NGX_CONF_2MORE,
@@ -1811,7 +1818,14 @@ ngx_http_set_exten(ngx_http_request_t *r)
 ngx_int_t
 ngx_http_set_etag(ngx_http_request_t *r)
 {
-    ngx_table_elt_t  *etag;
+    ngx_table_elt_t           *etag;
+    ngx_http_core_loc_conf_t  *clcf;
+    
+    clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
+    if (!clcf->etag) {
+        return NGX_OK;
+    }
 
     etag = ngx_list_push(&r->headers_out.headers);
     if (etag == NULL) {
@@ -3539,6 +3553,7 @@ ngx_http_core_create_loc_conf(ngx_conf_t *cf)
     clcf->recursive_error_pages = NGX_CONF_UNSET;
     clcf->server_tokens = NGX_CONF_UNSET;
     clcf->chunked_transfer_encoding = NGX_CONF_UNSET;
+    clcf->etag = NGX_CONF_UNSET;
     clcf->types_hash_max_size = NGX_CONF_UNSET_UINT;
     clcf->types_hash_bucket_size = NGX_CONF_UNSET_UINT;
 
@@ -3800,6 +3815,7 @@ ngx_http_core_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
     ngx_conf_merge_value(conf->server_tokens, prev->server_tokens, 1);
     ngx_conf_merge_value(conf->chunked_transfer_encoding,
                               prev->chunked_transfer_encoding, 1);
+    ngx_conf_merge_value(conf->etag, prev->etag, 1);
 
     ngx_conf_merge_ptr_value(conf->open_file_cache,
                               prev->open_file_cache, NULL);
index 52b3dde3cc5be3957db31d0d40bf8d9fb96cb667..b11bdcd90560060588d3a896f24a1e0d0c33f950 100644 (file)
@@ -392,6 +392,7 @@ struct ngx_http_core_loc_conf_s {
     ngx_flag_t    recursive_error_pages;   /* recursive_error_pages */
     ngx_flag_t    server_tokens;           /* server_tokens */
     ngx_flag_t    chunked_transfer_encoding; /* chunked_transfer_encoding */
+    ngx_flag_t    etag;                    /* etag */
 
 #if (NGX_HTTP_GZIP)
     ngx_flag_t    gzip_vary;               /* gzip_vary */