Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

fix the issue that module is not correctly etaged according to the co…

…nfig.
  • Loading branch information...
commit 59c2f44a195073ea75d832c644e12ec4d44ec568 1 parent 4303ba9
SilverFox zerda authored committed

Showing 1 changed file with 56 additions and 53 deletions. Show diff stats Hide diff stats

  1. +56 53 ngx_http_dynamic_etags_module.c
109 ngx_http_dynamic_etags_module.c
@@ -141,71 +141,74 @@ static ngx_int_t ngx_http_dynamic_etags_body_filter(ngx_http_request_t *r, ngx_c
141 141 ngx_uint_t i;
142 142
143 143 ctx = ngx_http_get_module_ctx(r, ngx_http_dynamic_etags_module);
144   -
145   - ctx = ngx_http_get_module_ctx(r, ngx_http_dynamic_etags_module);
146 144 if (ctx == NULL) {
147 145 return ngx_http_next_body_filter(r, in);
148 146 }
  147 +
  148 + ngx_http_dynamic_etags_loc_conf_t *loc_conf;
  149 + loc_conf = ngx_http_get_module_loc_conf(r, ngx_http_dynamic_etags_module);
  150 + if (1 == loc_conf->enable) {
  151 + ngx_md5_init(&md5);
  152 + for (chain_link = in; chain_link; chain_link = chain_link->next) {
  153 + ngx_md5_update(&md5, chain_link->buf->pos,
  154 + chain_link->buf->last - chain_link->buf->pos);
  155 + }
  156 + ngx_md5_final(digest, &md5);
149 157
150   - ngx_md5_init(&md5);
151   - for (chain_link = in; chain_link; chain_link = chain_link->next) {
152   - ngx_md5_update(&md5, chain_link->buf->pos,
153   - chain_link->buf->last - chain_link->buf->pos);
154   - }
155   - ngx_md5_final(digest, &md5);
156   -
157   - unsigned char* etag = ngx_pcalloc(r->pool, 34);
158   - etag[0] = etag[33] = '"';
159   - for ( i = 0 ; i < 16; i++ ) {
160   - etag[2*i+1] = hex[digest[i] >> 4];
161   - etag[2*i+2] = hex[digest[i] & 0xf];
162   - }
  158 + unsigned char* etag = ngx_pcalloc(r->pool, 34);
  159 + etag[0] = etag[33] = '"';
  160 + for ( i = 0 ; i < 16; i++ ) {
  161 + etag[2*i+1] = hex[digest[i] >> 4];
  162 + etag[2*i+2] = hex[digest[i] & 0xf];
  163 + }
163 164
164   - if(!r->headers_out.etag) {
165   - r->headers_out.etag = ngx_list_push(&r->headers_out.headers);
166   - }
  165 + if(!r->headers_out.etag) {
  166 + r->headers_out.etag = ngx_list_push(&r->headers_out.headers);
  167 + }
167 168
168   - r->headers_out.etag->hash = 1;
169   - r->headers_out.etag->key.len = sizeof("ETag") - 1;
170   - r->headers_out.etag->key.data = (u_char *) "ETag";
171   - r->headers_out.etag->value.len = 34;
172   - r->headers_out.etag->value.data = etag;
173   -
174   - /* look for If-None-Match in request headers */
175   - ngx_uint_t found=0;
176   - ngx_list_part_t *part = NULL;
177   - ngx_table_elt_t *header = NULL;
178   - ngx_table_elt_t if_none_match;
179   - part = &r->headers_in.headers.part;
180   - header = part->elts;
181   - for ( i = 0 ; ; i++ ) {
182   - if ( i >= part->nelts) {
183   - if ( part->next == NULL ) {
184   - break;
  169 + r->headers_out.etag->hash = 1;
  170 + r->headers_out.etag->key.len = sizeof("ETag") - 1;
  171 + r->headers_out.etag->key.data = (u_char *) "ETag";
  172 + r->headers_out.etag->value.len = 34;
  173 + r->headers_out.etag->value.data = etag;
  174 +
  175 + /* look for If-None-Match in request headers */
  176 + ngx_uint_t found=0;
  177 + ngx_list_part_t *part = NULL;
  178 + ngx_table_elt_t *header = NULL;
  179 + ngx_table_elt_t if_none_match;
  180 + part = &r->headers_in.headers.part;
  181 + header = part->elts;
  182 + for ( i = 0 ; ; i++ ) {
  183 + if ( i >= part->nelts) {
  184 + if ( part->next == NULL ) {
  185 + break;
  186 + }
  187 +
  188 + part = part->next;
  189 + header = part->elts;
  190 + i = 0;
185 191 }
186 192
187   - part = part->next;
188   - header = part->elts;
189   - i = 0;
190   - }
191   -
192   - if ( ngx_strcmp(header[i].key.data, "If-None-Match") == 0 ) {
193   - if_none_match = header[i];
194   - found = 1;
195   - break;
  193 + if ( ngx_strcmp(header[i].key.data, "If-None-Match") == 0 ) {
  194 + if_none_match = header[i];
  195 + found = 1;
  196 + break;
  197 + }
196 198 }
197   - }
198 199
199   - if ( found ) {
200   - if ( ngx_strncmp(r->headers_out.etag->value.data, if_none_match.value.data, r->headers_out.etag->value.len) == 0 ) {
  200 + if ( found ) {
  201 + if ( ngx_strncmp(r->headers_out.etag->value.data, if_none_match.value.data, r->headers_out.etag->value.len) == 0 ) {
201 202
202   - r->headers_out.status = NGX_HTTP_NOT_MODIFIED;
203   - r->headers_out.status_line.len = 0;
204   - r->headers_out.content_type.len = 0;
205   - ngx_http_clear_content_length(r);
206   - ngx_http_clear_accept_ranges(r);
  203 + r->headers_out.status = NGX_HTTP_NOT_MODIFIED;
  204 + r->headers_out.status_line.len = 0;
  205 + r->headers_out.content_type.len = 0;
  206 + ngx_http_clear_content_length(r);
  207 + ngx_http_clear_accept_ranges(r);
  208 + }
207 209 }
208   - }
  210 + }
  211 +
209 212
210 213 rc = ngx_http_next_header_filter(r);
211 214 if (rc == NGX_ERROR || rc > NGX_OK) {

0 comments on commit 59c2f44

Gao

static file content and php content is same,but etag is different,Why?

Please sign in to comment.
Something went wrong with that request. Please try again.