95
95
struct sockaddr *s);
97
97
ngx_int_t ngx_http_cache_purge_send_response(ngx_http_request_t *r);
98
# if (nginx_version >= 1007009)
99
ngx_int_t ngx_http_cache_purge_cache_get(ngx_http_request_t *r,
100
ngx_http_upstream_t *u, ngx_http_file_cache_t **cache);
101
# endif /* nginx_version >= 1007009 */
98
102
ngx_int_t ngx_http_cache_purge_init(ngx_http_request_t *r,
99
103
ngx_http_file_cache_t *cache, ngx_http_complex_value_t *cache_key);
100
104
void ngx_http_cache_purge_handler(ngx_http_request_t *r);
195
199
# if (NGX_HTTP_FASTCGI)
196
200
extern ngx_module_t ngx_http_fastcgi_module;
202
# if (nginx_version >= 1007009)
205
ngx_array_t caches; /* ngx_http_file_cache_t * */
206
} ngx_http_fastcgi_main_conf_t;
208
# endif /* nginx_version >= 1007009 */
198
210
# if (nginx_version >= 1007008)
253
265
ngx_http_core_loc_conf_t *clcf;
254
266
ngx_http_fastcgi_loc_conf_t *flcf;
255
267
ngx_str_t *value;
268
# if (nginx_version >= 1007009)
269
ngx_http_complex_value_t cv;
270
# endif /* nginx_version >= 1007009 */
257
272
cplcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_cache_purge_module);
272
287
flcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_fastcgi_module);
289
# if (nginx_version >= 1007009)
290
if (flcf->upstream.cache > 0)
274
292
if (flcf->upstream.cache != NGX_CONF_UNSET_PTR
275
293
&& flcf->upstream.cache != NULL)
294
# endif /* nginx_version >= 1007009 */
277
296
return "is incompatible with \"fastcgi_cache\"";
281
300
return "is incompatible with \"fastcgi_pass\"";
284
if (flcf->upstream.store > 0 || flcf->upstream.store_lengths) {
303
if (flcf->upstream.store > 0
304
# if (nginx_version < 1007009)
305
|| flcf->upstream.store_lengths
306
# endif /* nginx_version >= 1007009 */
285
309
return "is incompatible with \"fastcgi_store\"";
288
312
value = cf->args->elts;
290
314
/* set fastcgi_cache part */
315
# if (nginx_version >= 1007009)
317
flcf->upstream.cache = 1;
319
ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
322
ccv.value = &value[1];
323
ccv.complex_value = &cv;
325
if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
326
return NGX_CONF_ERROR;
329
if (cv.lengths != NULL) {
331
flcf->upstream.cache_value = ngx_palloc(cf->pool,
332
sizeof(ngx_http_complex_value_t));
333
if (flcf->upstream.cache_value == NULL) {
334
return NGX_CONF_ERROR;
337
*flcf->upstream.cache_value = cv;
341
flcf->upstream.cache_zone = ngx_shared_memory_add(cf, &value[1], 0,
342
&ngx_http_fastcgi_module);
343
if (flcf->upstream.cache_zone == NULL) {
344
return NGX_CONF_ERROR;
291
350
flcf->upstream.cache = ngx_shared_memory_add(cf, &value[1], 0,
292
351
&ngx_http_fastcgi_module);
293
352
if (flcf->upstream.cache == NULL) {
294
353
return NGX_CONF_ERROR;
356
# endif /* nginx_version >= 1007009 */
297
358
/* set fastcgi_cache_key part */
298
359
ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
318
379
ngx_http_fastcgi_cache_purge_handler(ngx_http_request_t *r)
320
ngx_http_fastcgi_loc_conf_t *flcf;
381
ngx_http_file_cache_t *cache;
382
ngx_http_fastcgi_loc_conf_t *flcf;
383
# if (nginx_version >= 1007009)
384
ngx_http_fastcgi_main_conf_t *fmcf;
386
# endif /* nginx_version >= 1007009 */
388
if (ngx_http_upstream_create(r) != NGX_OK) {
389
return NGX_HTTP_INTERNAL_SERVER_ERROR;
322
392
flcf = ngx_http_get_module_loc_conf(r, ngx_http_fastcgi_module);
324
if (ngx_http_cache_purge_init(r, flcf->upstream.cache->data,
394
r->upstream->conf = &flcf->upstream;
396
# if (nginx_version >= 1007009)
398
fmcf = ngx_http_get_module_main_conf(r, ngx_http_fastcgi_module);
400
r->upstream->caches = &fmcf->caches;
402
rc = ngx_http_cache_purge_cache_get(r, r->upstream, &cache);
409
cache = flcf->upstream.cache->data;
411
# endif /* nginx_version >= 1007009 */
413
if (ngx_http_cache_purge_init(r, cache, &flcf->cache_key) != NGX_OK) {
328
414
return NGX_HTTP_INTERNAL_SERVER_ERROR;
350
436
} ngx_http_proxy_vars_t;
438
# if (nginx_version >= 1007009)
441
ngx_array_t caches; /* ngx_http_file_cache_t * */
442
} ngx_http_proxy_main_conf_t;
444
# endif /* nginx_version >= 1007009 */
352
446
# if (nginx_version >= 1007008)
442
536
ngx_http_core_loc_conf_t *clcf;
443
537
ngx_http_proxy_loc_conf_t *plcf;
444
538
ngx_str_t *value;
539
# if (nginx_version >= 1007009)
540
ngx_http_complex_value_t cv;
541
# endif /* nginx_version >= 1007009 */
446
543
cplcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_cache_purge_module);
461
558
plcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_proxy_module);
560
# if (nginx_version >= 1007009)
561
if (plcf->upstream.cache > 0)
463
563
if (plcf->upstream.cache != NGX_CONF_UNSET_PTR
464
564
&& plcf->upstream.cache != NULL)
565
# endif /* nginx_version >= 1007009 */
466
567
return "is incompatible with \"proxy_cache\"";
470
571
return "is incompatible with \"proxy_pass\"";
473
if (plcf->upstream.store > 0 || plcf->upstream.store_lengths) {
574
if (plcf->upstream.store > 0
575
# if (nginx_version < 1007009)
576
|| plcf->upstream.store_lengths
577
# endif /* nginx_version >= 1007009 */
474
580
return "is incompatible with \"proxy_store\"";
477
583
value = cf->args->elts;
479
585
/* set proxy_cache part */
586
# if (nginx_version >= 1007009)
588
plcf->upstream.cache = 1;
590
ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
593
ccv.value = &value[1];
594
ccv.complex_value = &cv;
596
if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
597
return NGX_CONF_ERROR;
600
if (cv.lengths != NULL) {
602
plcf->upstream.cache_value = ngx_palloc(cf->pool,
603
sizeof(ngx_http_complex_value_t));
604
if (plcf->upstream.cache_value == NULL) {
605
return NGX_CONF_ERROR;
608
*plcf->upstream.cache_value = cv;
612
plcf->upstream.cache_zone = ngx_shared_memory_add(cf, &value[1], 0,
613
&ngx_http_proxy_module);
614
if (plcf->upstream.cache_zone == NULL) {
615
return NGX_CONF_ERROR;
480
621
plcf->upstream.cache = ngx_shared_memory_add(cf, &value[1], 0,
481
622
&ngx_http_proxy_module);
482
623
if (plcf->upstream.cache == NULL) {
483
624
return NGX_CONF_ERROR;
627
# endif /* nginx_version >= 1007009 */
486
629
/* set proxy_cache_key part */
487
630
ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
507
650
ngx_http_proxy_cache_purge_handler(ngx_http_request_t *r)
509
ngx_http_proxy_loc_conf_t *plcf;
652
ngx_http_file_cache_t *cache;
653
ngx_http_proxy_loc_conf_t *plcf;
654
# if (nginx_version >= 1007009)
655
ngx_http_proxy_main_conf_t *pmcf;
657
# endif /* nginx_version >= 1007009 */
659
if (ngx_http_upstream_create(r) != NGX_OK) {
660
return NGX_HTTP_INTERNAL_SERVER_ERROR;
511
663
plcf = ngx_http_get_module_loc_conf(r, ngx_http_proxy_module);
513
if (ngx_http_cache_purge_init(r, plcf->upstream.cache->data,
665
r->upstream->conf = &plcf->upstream;
667
# if (nginx_version >= 1007009)
669
pmcf = ngx_http_get_module_main_conf(r, ngx_http_proxy_module);
671
r->upstream->caches = &pmcf->caches;
673
rc = ngx_http_cache_purge_cache_get(r, r->upstream, &cache);
680
cache = plcf->upstream.cache->data;
682
# endif /* nginx_version >= 1007009 */
684
if (ngx_http_cache_purge_init(r, cache, &plcf->cache_key) != NGX_OK) {
517
685
return NGX_HTTP_INTERNAL_SERVER_ERROR;
530
698
# if (NGX_HTTP_SCGI)
531
699
extern ngx_module_t ngx_http_scgi_module;
701
# if (nginx_version >= 1007009)
704
ngx_array_t caches; /* ngx_http_file_cache_t * */
705
} ngx_http_scgi_main_conf_t;
707
# endif /* nginx_version >= 1007009 */
533
709
# if (nginx_version >= 1007008)
573
749
ngx_http_core_loc_conf_t *clcf;
574
750
ngx_http_scgi_loc_conf_t *slcf;
575
751
ngx_str_t *value;
752
# if (nginx_version >= 1007009)
753
ngx_http_complex_value_t cv;
754
# endif /* nginx_version >= 1007009 */
577
756
cplcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_cache_purge_module);
592
771
slcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_scgi_module);
773
# if (nginx_version >= 1007009)
774
if (slcf->upstream.cache > 0)
594
776
if (slcf->upstream.cache != NGX_CONF_UNSET_PTR
595
777
&& slcf->upstream.cache != NULL)
778
# endif /* nginx_version >= 1007009 */
597
780
return "is incompatible with \"scgi_cache\"";
601
784
return "is incompatible with \"scgi_pass\"";
604
if (slcf->upstream.store > 0 || slcf->upstream.store_lengths) {
787
if (slcf->upstream.store > 0
788
# if (nginx_version < 1007009)
789
|| slcf->upstream.store_lengths
790
# endif /* nginx_version >= 1007009 */
605
793
return "is incompatible with \"scgi_store\"";
608
796
value = cf->args->elts;
610
798
/* set scgi_cache part */
799
# if (nginx_version >= 1007009)
801
slcf->upstream.cache = 1;
803
ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
806
ccv.value = &value[1];
807
ccv.complex_value = &cv;
809
if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
810
return NGX_CONF_ERROR;
813
if (cv.lengths != NULL) {
815
slcf->upstream.cache_value = ngx_palloc(cf->pool,
816
sizeof(ngx_http_complex_value_t));
817
if (slcf->upstream.cache_value == NULL) {
818
return NGX_CONF_ERROR;
821
*slcf->upstream.cache_value = cv;
825
slcf->upstream.cache_zone = ngx_shared_memory_add(cf, &value[1], 0,
826
&ngx_http_scgi_module);
827
if (slcf->upstream.cache_zone == NULL) {
828
return NGX_CONF_ERROR;
611
834
slcf->upstream.cache = ngx_shared_memory_add(cf, &value[1], 0,
612
835
&ngx_http_scgi_module);
613
836
if (slcf->upstream.cache == NULL) {
614
837
return NGX_CONF_ERROR;
840
# endif /* nginx_version >= 1007009 */
617
842
/* set scgi_cache_key part */
618
843
ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
638
863
ngx_http_scgi_cache_purge_handler(ngx_http_request_t *r)
640
ngx_http_scgi_loc_conf_t *slcf;
865
ngx_http_file_cache_t *cache;
866
ngx_http_scgi_loc_conf_t *slcf;
867
# if (nginx_version >= 1007009)
868
ngx_http_scgi_main_conf_t *smcf;
870
# endif /* nginx_version >= 1007009 */
872
if (ngx_http_upstream_create(r) != NGX_OK) {
873
return NGX_HTTP_INTERNAL_SERVER_ERROR;
642
876
slcf = ngx_http_get_module_loc_conf(r, ngx_http_scgi_module);
644
if (ngx_http_cache_purge_init(r, slcf->upstream.cache->data,
878
r->upstream->conf = &slcf->upstream;
880
# if (nginx_version >= 1007009)
882
smcf = ngx_http_get_module_main_conf(r, ngx_http_scgi_module);
884
r->upstream->caches = &smcf->caches;
886
rc = ngx_http_cache_purge_cache_get(r, r->upstream, &cache);
893
cache = slcf->upstream.cache->data;
895
# endif /* nginx_version >= 1007009 */
897
if (ngx_http_cache_purge_init(r, cache, &slcf->cache_key) != NGX_OK) {
648
898
return NGX_HTTP_INTERNAL_SERVER_ERROR;
661
911
# if (NGX_HTTP_UWSGI)
662
912
extern ngx_module_t ngx_http_uwsgi_module;
914
# if (nginx_version >= 1007009)
917
ngx_array_t caches; /* ngx_http_file_cache_t * */
918
} ngx_http_uwsgi_main_conf_t;
920
# endif /* nginx_version >= 1007009 */
664
922
# if (nginx_version >= 1007008)
727
985
ngx_http_core_loc_conf_t *clcf;
728
986
ngx_http_uwsgi_loc_conf_t *ulcf;
729
987
ngx_str_t *value;
988
# if (nginx_version >= 1007009)
989
ngx_http_complex_value_t cv;
990
# endif /* nginx_version >= 1007009 */
731
992
cplcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_cache_purge_module);
746
1007
ulcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_uwsgi_module);
1009
# if (nginx_version >= 1007009)
1010
if (ulcf->upstream.cache > 0)
748
1012
if (ulcf->upstream.cache != NGX_CONF_UNSET_PTR
749
1013
&& ulcf->upstream.cache != NULL)
1014
# endif /* nginx_version >= 1007009 */
751
1016
return "is incompatible with \"uwsgi_cache\"";
755
1020
return "is incompatible with \"uwsgi_pass\"";
758
if (ulcf->upstream.store > 0 || ulcf->upstream.store_lengths) {
1023
if (ulcf->upstream.store > 0
1024
# if (nginx_version < 1007009)
1025
|| ulcf->upstream.store_lengths
1026
# endif /* nginx_version >= 1007009 */
759
1029
return "is incompatible with \"uwsgi_store\"";
762
1032
value = cf->args->elts;
764
1034
/* set uwsgi_cache part */
1035
# if (nginx_version >= 1007009)
1037
ulcf->upstream.cache = 1;
1039
ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
1042
ccv.value = &value[1];
1043
ccv.complex_value = &cv;
1045
if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
1046
return NGX_CONF_ERROR;
1049
if (cv.lengths != NULL) {
1051
ulcf->upstream.cache_value = ngx_palloc(cf->pool,
1052
sizeof(ngx_http_complex_value_t));
1053
if (ulcf->upstream.cache_value == NULL) {
1054
return NGX_CONF_ERROR;
1057
*ulcf->upstream.cache_value = cv;
1061
ulcf->upstream.cache_zone = ngx_shared_memory_add(cf, &value[1], 0,
1062
&ngx_http_uwsgi_module);
1063
if (ulcf->upstream.cache_zone == NULL) {
1064
return NGX_CONF_ERROR;
765
1070
ulcf->upstream.cache = ngx_shared_memory_add(cf, &value[1], 0,
766
1071
&ngx_http_uwsgi_module);
767
1072
if (ulcf->upstream.cache == NULL) {
768
1073
return NGX_CONF_ERROR;
1076
# endif /* nginx_version >= 1007009 */
771
1078
/* set uwsgi_cache_key part */
772
1079
ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
792
1099
ngx_http_uwsgi_cache_purge_handler(ngx_http_request_t *r)
794
ngx_http_uwsgi_loc_conf_t *ulcf;
1101
ngx_http_file_cache_t *cache;
1102
ngx_http_uwsgi_loc_conf_t *ulcf;
1103
# if (nginx_version >= 1007009)
1104
ngx_http_uwsgi_main_conf_t *umcf;
1106
# endif /* nginx_version >= 1007009 */
1108
if (ngx_http_upstream_create(r) != NGX_OK) {
1109
return NGX_HTTP_INTERNAL_SERVER_ERROR;
796
1112
ulcf = ngx_http_get_module_loc_conf(r, ngx_http_uwsgi_module);
798
if (ngx_http_cache_purge_init(r, ulcf->upstream.cache->data,
1114
r->upstream->conf = &ulcf->upstream;
1116
# if (nginx_version >= 1007009)
1118
umcf = ngx_http_get_module_main_conf(r, ngx_http_uwsgi_module);
1120
r->upstream->caches = &umcf->caches;
1122
rc = ngx_http_cache_purge_cache_get(r, r->upstream, &cache);
1129
cache = ulcf->upstream.cache->data;
1131
# endif /* nginx_version >= 1007009 */
1133
if (ngx_http_cache_purge_init(r, cache, &ulcf->cache_key) != NGX_OK) {
802
1134
return NGX_HTTP_INTERNAL_SERVER_ERROR;
972
1304
return ngx_http_output_filter(r, &out);
1307
# if (nginx_version >= 1007009)
1310
* Based on: ngx_http_upstream.c/ngx_http_upstream_cache_get
1311
* Copyright (C) Igor Sysoev
1312
* Copyright (C) Nginx, Inc.
1315
ngx_http_cache_purge_cache_get(ngx_http_request_t *r, ngx_http_upstream_t *u,
1316
ngx_http_file_cache_t **cache)
1318
ngx_str_t *name, val;
1320
ngx_http_file_cache_t **caches;
1322
if (u->conf->cache_zone) {
1323
*cache = u->conf->cache_zone->data;
1327
if (ngx_http_complex_value(r, u->conf->cache_value, &val) != NGX_OK) {
1332
|| (val.len == 3 && ngx_strncmp(val.data, "off", 3) == 0))
1334
return NGX_DECLINED;
1337
caches = u->caches->elts;
1339
for (i = 0; i < u->caches->nelts; i++) {
1340
name = &caches[i]->shm_zone->shm.name;
1342
if (name->len == val.len
1343
&& ngx_strncmp(name->data, val.data, val.len) == 0)
1350
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
1351
"cache \"%V\" not found", &val);
1356
# endif /* nginx_version >= 1007009 */
976
1359
ngx_http_cache_purge_init(ngx_http_request_t *r, ngx_http_file_cache_t *cache,
977
1360
ngx_http_complex_value_t *cache_key)