Skip to content

Commit 69d87b6

Browse files
committed
checked in t/no-cache.t; now turning srcache_request_cache_control on will also honor the request header "Cache-Control: no-store".
1 parent 00b30f7 commit 69d87b6

File tree

5 files changed

+595
-12
lines changed

5 files changed

+595
-12
lines changed

src/ngx_http_srcache_filter_module.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,7 @@ ngx_http_srcache_access_handler(ngx_http_request_t *r)
758758
ngx_http_srcache_ctx_t *ctx;
759759
ngx_chain_t *cl;
760760
size_t len;
761+
unsigned no_store;
761762

762763
if (r != r->main) {
763764
return NGX_DECLINED;
@@ -786,20 +787,27 @@ ngx_http_srcache_access_handler(ngx_http_request_t *r)
786787
}
787788

788789
if (conf->req_cache_control) {
789-
if (ngx_http_srcache_request_no_cache(r) == NGX_OK) {
790+
if (ngx_http_srcache_request_no_cache(r, &no_store) == NGX_OK) {
790791
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
791792
"srcache_fetch skipped due to request headers "
792793
"\"Cache-Control: no-cache\" or \"Pragma: no-cache\"");
793794

794-
/* register a ctx to give a chance to srcache_store to run */
795+
if (!no_store) {
796+
/* register a ctx to give a chance to srcache_store to run */
795797

796-
ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_srcache_filter_module));
798+
ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_srcache_filter_module));
797799

798-
if (ctx == NULL) {
799-
return NGX_HTTP_INTERNAL_SERVER_ERROR;
800-
}
800+
if (ctx == NULL) {
801+
return NGX_HTTP_INTERNAL_SERVER_ERROR;
802+
}
801803

802-
ngx_http_set_ctx(r, ctx, ngx_http_srcache_filter_module);
804+
ngx_http_set_ctx(r, ctx, ngx_http_srcache_filter_module);
805+
806+
} else {
807+
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
808+
"srcache_store skipped due to request header "
809+
"\"Cache-Control: no-store\"");
810+
}
803811

804812
return NGX_DECLINED;
805813
}

src/ngx_http_srcache_util.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -383,17 +383,21 @@ ngx_http_srcache_set_content_length_header(ngx_http_request_t *r, off_t len)
383383

384384

385385
ngx_int_t
386-
ngx_http_srcache_request_no_cache(ngx_http_request_t *r)
386+
ngx_http_srcache_request_no_cache(ngx_http_request_t *r, unsigned *no_store)
387387
{
388388
ngx_table_elt_t *h;
389389
ngx_list_part_t *part;
390390
u_char *p;
391391
u_char *last;
392392
ngx_uint_t i;
393+
unsigned no_cache;
393394

394395
part = &r->headers_in.headers.part;
395396
h = part->elts;
396397

398+
*no_store = 0;
399+
no_cache = 0;
400+
397401
for (i = 0; /* void */; i++) {
398402

399403
if (i >= part->nelts) {
@@ -413,9 +417,16 @@ ngx_http_srcache_request_no_cache(ngx_http_request_t *r)
413417
p = h[i].value.data;
414418
last = p + h[i].value.len;
415419

420+
if (!*no_store
421+
&& ngx_strlcasestrn(p, last, (u_char *) "no-store", 8 - 1)
422+
!= NULL)
423+
{
424+
*no_store = 1;
425+
}
426+
416427
if (ngx_strlcasestrn(p, last, (u_char *) "no-cache", 8 - 1) != NULL)
417428
{
418-
return NGX_OK;
429+
no_cache = 1;
419430
}
420431

421432
continue;
@@ -430,12 +441,12 @@ ngx_http_srcache_request_no_cache(ngx_http_request_t *r)
430441

431442
if (ngx_strlcasestrn(p, last, (u_char *) "no-cache", 8 - 1) != NULL)
432443
{
433-
return NGX_OK;
444+
no_cache = 1;
434445
}
435446
}
436447
}
437448

438-
return NGX_DECLINED;
449+
return no_cache ? NGX_OK : NGX_DECLINED;
439450
}
440451

441452

src/ngx_http_srcache_util.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ ngx_int_t ngx_http_srcache_add_copy_chain(ngx_pool_t *pool,
3434
ngx_chain_t **chain, ngx_chain_t *in);
3535
ngx_int_t ngx_http_srcache_post_request_at_head(ngx_http_request_t *r,
3636
ngx_http_posted_request_t *pr);
37-
ngx_int_t ngx_http_srcache_request_no_cache(ngx_http_request_t *r);
37+
ngx_int_t ngx_http_srcache_request_no_cache(ngx_http_request_t *r,
38+
unsigned *no_store);
3839
ngx_int_t ngx_http_srcache_response_no_cache(ngx_http_request_t *r,
3940
ngx_http_srcache_loc_conf_t *conf);
4041

0 commit comments

Comments
 (0)