~titusx/nginx/module-cache-purge

« back to all changes in this revision

Viewing changes to ngx_cache_purge_module.c

  • Committer: Piotr Sikora
  • Date: 2014-12-23 12:01:10 UTC
  • Revision ID: git-v1:065f0cae56fc5720db636885ce5b2fbaf6f09f8c
Fix compatibility with nginx-1.7.9+.

Change-Id: I262a13f007724c40496bf8c44f9518cb1ee75663
Signed-off-by: Piotr Sikora <piotr.sikora@frickle.com>

Show diffs side-by-side

added added

removed removed

Lines of Context:
95
95
    struct sockaddr *s);
96
96
 
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;
197
201
 
 
202
#  if (nginx_version >= 1007009)
 
203
 
 
204
typedef struct {
 
205
    ngx_array_t                    caches;  /* ngx_http_file_cache_t * */
 
206
} ngx_http_fastcgi_main_conf_t;
 
207
 
 
208
#  endif /* nginx_version >= 1007009 */
 
209
 
198
210
#  if (nginx_version >= 1007008)
199
211
 
200
212
typedef struct {
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 */
256
271
 
257
272
    cplcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_cache_purge_module);
258
273
 
271
286
 
272
287
    flcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_fastcgi_module);
273
288
 
 
289
#  if (nginx_version >= 1007009)
 
290
    if (flcf->upstream.cache > 0)
 
291
#  else
274
292
    if (flcf->upstream.cache != NGX_CONF_UNSET_PTR
275
293
        && flcf->upstream.cache != NULL)
 
294
#  endif /* nginx_version >= 1007009 */
276
295
    {
277
296
        return "is incompatible with \"fastcgi_cache\"";
278
297
    }
281
300
        return "is incompatible with \"fastcgi_pass\"";
282
301
    }
283
302
 
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 */
 
307
       )
 
308
    {
285
309
        return "is incompatible with \"fastcgi_store\"";
286
310
    }
287
311
 
288
312
    value = cf->args->elts;
289
313
 
290
314
    /* set fastcgi_cache part */
 
315
#  if (nginx_version >= 1007009)
 
316
 
 
317
    flcf->upstream.cache = 1;
 
318
 
 
319
    ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
 
320
 
 
321
    ccv.cf = cf;
 
322
    ccv.value = &value[1];
 
323
    ccv.complex_value = &cv;
 
324
 
 
325
    if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
 
326
        return NGX_CONF_ERROR;
 
327
    }
 
328
 
 
329
    if (cv.lengths != NULL) {
 
330
 
 
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;
 
335
        }
 
336
 
 
337
        *flcf->upstream.cache_value = cv;
 
338
 
 
339
    } else {
 
340
 
 
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;
 
345
        }
 
346
    }
 
347
 
 
348
#  else
 
349
 
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;
295
354
    }
296
355
 
 
356
#  endif /* nginx_version >= 1007009 */
 
357
 
297
358
    /* set fastcgi_cache_key part */
298
359
    ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
299
360
 
317
378
ngx_int_t
318
379
ngx_http_fastcgi_cache_purge_handler(ngx_http_request_t *r)
319
380
{
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;
 
385
    ngx_int_t                      rc;
 
386
#  endif /* nginx_version >= 1007009 */
 
387
 
 
388
    if (ngx_http_upstream_create(r) != NGX_OK) {
 
389
        return NGX_HTTP_INTERNAL_SERVER_ERROR;
 
390
    }
321
391
 
322
392
    flcf = ngx_http_get_module_loc_conf(r, ngx_http_fastcgi_module);
323
393
 
324
 
    if (ngx_http_cache_purge_init(r, flcf->upstream.cache->data,
325
 
                                  &flcf->cache_key)
326
 
        != NGX_OK)
327
 
    {
 
394
    r->upstream->conf = &flcf->upstream;
 
395
 
 
396
#  if (nginx_version >= 1007009)
 
397
 
 
398
    fmcf = ngx_http_get_module_main_conf(r, ngx_http_fastcgi_module);
 
399
 
 
400
    r->upstream->caches = &fmcf->caches;
 
401
 
 
402
    rc = ngx_http_cache_purge_cache_get(r, r->upstream, &cache);
 
403
    if (rc != NGX_OK) {
 
404
        return rc;
 
405
    }
 
406
 
 
407
#  else
 
408
 
 
409
    cache = flcf->upstream.cache->data;
 
410
 
 
411
#  endif /* nginx_version >= 1007009 */
 
412
 
 
413
    if (ngx_http_cache_purge_init(r, cache, &flcf->cache_key) != NGX_OK) {
328
414
        return NGX_HTTP_INTERNAL_SERVER_ERROR;
329
415
    }
330
416
 
349
435
    ngx_str_t                      uri;
350
436
} ngx_http_proxy_vars_t;
351
437
 
 
438
#  if (nginx_version >= 1007009)
 
439
 
 
440
typedef struct {
 
441
    ngx_array_t                    caches;  /* ngx_http_file_cache_t * */
 
442
} ngx_http_proxy_main_conf_t;
 
443
 
 
444
#  endif /* nginx_version >= 1007009 */
 
445
 
352
446
#  if (nginx_version >= 1007008)
353
447
 
354
448
typedef struct {
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 */
445
542
 
446
543
    cplcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_cache_purge_module);
447
544
 
460
557
 
461
558
    plcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_proxy_module);
462
559
 
 
560
#  if (nginx_version >= 1007009)
 
561
    if (plcf->upstream.cache > 0)
 
562
#  else
463
563
    if (plcf->upstream.cache != NGX_CONF_UNSET_PTR
464
564
        && plcf->upstream.cache != NULL)
 
565
#  endif /* nginx_version >= 1007009 */
465
566
    {
466
567
        return "is incompatible with \"proxy_cache\"";
467
568
    }
470
571
        return "is incompatible with \"proxy_pass\"";
471
572
    }
472
573
 
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 */
 
578
       )
 
579
    {
474
580
        return "is incompatible with \"proxy_store\"";
475
581
    }
476
582
 
477
583
    value = cf->args->elts;
478
584
 
479
585
    /* set proxy_cache part */
 
586
#  if (nginx_version >= 1007009)
 
587
 
 
588
    plcf->upstream.cache = 1;
 
589
 
 
590
    ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
 
591
 
 
592
    ccv.cf = cf;
 
593
    ccv.value = &value[1];
 
594
    ccv.complex_value = &cv;
 
595
 
 
596
    if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
 
597
        return NGX_CONF_ERROR;
 
598
    }
 
599
 
 
600
    if (cv.lengths != NULL) {
 
601
 
 
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;
 
606
        }
 
607
 
 
608
        *plcf->upstream.cache_value = cv;
 
609
 
 
610
    } else {
 
611
 
 
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;
 
616
        }
 
617
    }
 
618
 
 
619
#  else
 
620
 
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;
484
625
    }
485
626
 
 
627
#  endif /* nginx_version >= 1007009 */
 
628
 
486
629
    /* set proxy_cache_key part */
487
630
    ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
488
631
 
506
649
ngx_int_t
507
650
ngx_http_proxy_cache_purge_handler(ngx_http_request_t *r)
508
651
{
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;
 
656
    ngx_int_t                    rc;
 
657
#  endif /* nginx_version >= 1007009 */
 
658
 
 
659
    if (ngx_http_upstream_create(r) != NGX_OK) {
 
660
        return NGX_HTTP_INTERNAL_SERVER_ERROR;
 
661
    }
510
662
 
511
663
    plcf = ngx_http_get_module_loc_conf(r, ngx_http_proxy_module);
512
664
 
513
 
    if (ngx_http_cache_purge_init(r, plcf->upstream.cache->data,
514
 
                                  &plcf->cache_key)
515
 
        != NGX_OK)
516
 
    {
 
665
    r->upstream->conf = &plcf->upstream;
 
666
 
 
667
#  if (nginx_version >= 1007009)
 
668
 
 
669
    pmcf = ngx_http_get_module_main_conf(r, ngx_http_proxy_module);
 
670
 
 
671
    r->upstream->caches = &pmcf->caches;
 
672
 
 
673
    rc = ngx_http_cache_purge_cache_get(r, r->upstream, &cache);
 
674
    if (rc != NGX_OK) {
 
675
        return rc;
 
676
    }
 
677
 
 
678
#  else
 
679
 
 
680
    cache = plcf->upstream.cache->data;
 
681
 
 
682
#  endif /* nginx_version >= 1007009 */
 
683
 
 
684
    if (ngx_http_cache_purge_init(r, cache, &plcf->cache_key) != NGX_OK) {
517
685
        return NGX_HTTP_INTERNAL_SERVER_ERROR;
518
686
    }
519
687
 
530
698
# if (NGX_HTTP_SCGI)
531
699
extern ngx_module_t  ngx_http_scgi_module;
532
700
 
 
701
#  if (nginx_version >= 1007009)
 
702
 
 
703
typedef struct {
 
704
    ngx_array_t                caches;  /* ngx_http_file_cache_t * */
 
705
} ngx_http_scgi_main_conf_t;
 
706
 
 
707
#  endif /* nginx_version >= 1007009 */
 
708
 
533
709
#  if (nginx_version >= 1007008)
534
710
 
535
711
typedef struct {
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 */
576
755
 
577
756
    cplcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_cache_purge_module);
578
757
 
591
770
 
592
771
    slcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_scgi_module);
593
772
 
 
773
#  if (nginx_version >= 1007009)
 
774
    if (slcf->upstream.cache > 0)
 
775
#  else
594
776
    if (slcf->upstream.cache != NGX_CONF_UNSET_PTR
595
777
        && slcf->upstream.cache != NULL)
 
778
#  endif /* nginx_version >= 1007009 */
596
779
    {
597
780
        return "is incompatible with \"scgi_cache\"";
598
781
    }
601
784
        return "is incompatible with \"scgi_pass\"";
602
785
    }
603
786
 
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 */
 
791
       )
 
792
    {
605
793
        return "is incompatible with \"scgi_store\"";
606
794
    }
607
795
 
608
796
    value = cf->args->elts;
609
797
 
610
798
    /* set scgi_cache part */
 
799
#  if (nginx_version >= 1007009)
 
800
 
 
801
    slcf->upstream.cache = 1;
 
802
 
 
803
    ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
 
804
 
 
805
    ccv.cf = cf;
 
806
    ccv.value = &value[1];
 
807
    ccv.complex_value = &cv;
 
808
 
 
809
    if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
 
810
        return NGX_CONF_ERROR;
 
811
    }
 
812
 
 
813
    if (cv.lengths != NULL) {
 
814
 
 
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;
 
819
        }
 
820
 
 
821
        *slcf->upstream.cache_value = cv;
 
822
 
 
823
    } else {
 
824
 
 
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;
 
829
        }
 
830
    }
 
831
 
 
832
#  else
 
833
 
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;
615
838
    }
616
839
 
 
840
#  endif /* nginx_version >= 1007009 */
 
841
 
617
842
    /* set scgi_cache_key part */
618
843
    ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
619
844
 
637
862
ngx_int_t
638
863
ngx_http_scgi_cache_purge_handler(ngx_http_request_t *r)
639
864
{
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;
 
869
    ngx_int_t                   rc;
 
870
#  endif /* nginx_version >= 1007009 */
 
871
 
 
872
    if (ngx_http_upstream_create(r) != NGX_OK) {
 
873
        return NGX_HTTP_INTERNAL_SERVER_ERROR;
 
874
    }
641
875
 
642
876
    slcf = ngx_http_get_module_loc_conf(r, ngx_http_scgi_module);
643
877
 
644
 
    if (ngx_http_cache_purge_init(r, slcf->upstream.cache->data,
645
 
                                  &slcf->cache_key)
646
 
        != NGX_OK)
647
 
    {
 
878
    r->upstream->conf = &slcf->upstream;
 
879
 
 
880
#  if (nginx_version >= 1007009)
 
881
 
 
882
    smcf = ngx_http_get_module_main_conf(r, ngx_http_scgi_module);
 
883
 
 
884
    r->upstream->caches = &smcf->caches;
 
885
 
 
886
    rc = ngx_http_cache_purge_cache_get(r, r->upstream, &cache);
 
887
    if (rc != NGX_OK) {
 
888
        return rc;
 
889
    }
 
890
 
 
891
#  else
 
892
 
 
893
    cache = slcf->upstream.cache->data;
 
894
 
 
895
#  endif /* nginx_version >= 1007009 */
 
896
 
 
897
    if (ngx_http_cache_purge_init(r, cache, &slcf->cache_key) != NGX_OK) {
648
898
        return NGX_HTTP_INTERNAL_SERVER_ERROR;
649
899
    }
650
900
 
661
911
# if (NGX_HTTP_UWSGI)
662
912
extern ngx_module_t  ngx_http_uwsgi_module;
663
913
 
 
914
#  if (nginx_version >= 1007009)
 
915
 
 
916
typedef struct {
 
917
    ngx_array_t                caches;  /* ngx_http_file_cache_t * */
 
918
} ngx_http_uwsgi_main_conf_t;
 
919
 
 
920
#  endif /* nginx_version >= 1007009 */
 
921
 
664
922
#  if (nginx_version >= 1007008)
665
923
 
666
924
typedef struct {
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 */
730
991
 
731
992
    cplcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_cache_purge_module);
732
993
 
745
1006
 
746
1007
    ulcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_uwsgi_module);
747
1008
 
 
1009
#  if (nginx_version >= 1007009)
 
1010
    if (ulcf->upstream.cache > 0)
 
1011
#  else
748
1012
    if (ulcf->upstream.cache != NGX_CONF_UNSET_PTR
749
1013
        && ulcf->upstream.cache != NULL)
 
1014
#  endif /* nginx_version >= 1007009 */
750
1015
    {
751
1016
        return "is incompatible with \"uwsgi_cache\"";
752
1017
    }
755
1020
        return "is incompatible with \"uwsgi_pass\"";
756
1021
    }
757
1022
 
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 */
 
1027
       )
 
1028
    {
759
1029
        return "is incompatible with \"uwsgi_store\"";
760
1030
    }
761
1031
 
762
1032
    value = cf->args->elts;
763
1033
 
764
1034
    /* set uwsgi_cache part */
 
1035
#  if (nginx_version >= 1007009)
 
1036
 
 
1037
    ulcf->upstream.cache = 1;
 
1038
 
 
1039
    ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
 
1040
 
 
1041
    ccv.cf = cf;
 
1042
    ccv.value = &value[1];
 
1043
    ccv.complex_value = &cv;
 
1044
 
 
1045
    if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
 
1046
        return NGX_CONF_ERROR;
 
1047
    }
 
1048
 
 
1049
    if (cv.lengths != NULL) {
 
1050
 
 
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;
 
1055
        }
 
1056
 
 
1057
        *ulcf->upstream.cache_value = cv;
 
1058
 
 
1059
    } else {
 
1060
 
 
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;
 
1065
        }
 
1066
    }
 
1067
 
 
1068
#  else
 
1069
 
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;
769
1074
    }
770
1075
 
 
1076
#  endif /* nginx_version >= 1007009 */
 
1077
 
771
1078
    /* set uwsgi_cache_key part */
772
1079
    ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
773
1080
 
791
1098
ngx_int_t
792
1099
ngx_http_uwsgi_cache_purge_handler(ngx_http_request_t *r)
793
1100
{
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;
 
1105
    ngx_int_t                    rc;
 
1106
#  endif /* nginx_version >= 1007009 */
 
1107
 
 
1108
    if (ngx_http_upstream_create(r) != NGX_OK) {
 
1109
        return NGX_HTTP_INTERNAL_SERVER_ERROR;
 
1110
    }
795
1111
 
796
1112
    ulcf = ngx_http_get_module_loc_conf(r, ngx_http_uwsgi_module);
797
1113
 
798
 
    if (ngx_http_cache_purge_init(r, ulcf->upstream.cache->data,
799
 
                                  &ulcf->cache_key)
800
 
        != NGX_OK)
801
 
    {
 
1114
    r->upstream->conf = &ulcf->upstream;
 
1115
 
 
1116
#  if (nginx_version >= 1007009)
 
1117
 
 
1118
    umcf = ngx_http_get_module_main_conf(r, ngx_http_uwsgi_module);
 
1119
 
 
1120
    r->upstream->caches = &umcf->caches;
 
1121
 
 
1122
    rc = ngx_http_cache_purge_cache_get(r, r->upstream, &cache);
 
1123
    if (rc != NGX_OK) {
 
1124
        return rc;
 
1125
    }
 
1126
 
 
1127
#  else
 
1128
 
 
1129
    cache = ulcf->upstream.cache->data;
 
1130
 
 
1131
#  endif /* nginx_version >= 1007009 */
 
1132
 
 
1133
    if (ngx_http_cache_purge_init(r, cache, &ulcf->cache_key) != NGX_OK) {
802
1134
        return NGX_HTTP_INTERNAL_SERVER_ERROR;
803
1135
    }
804
1136
 
972
1304
    return ngx_http_output_filter(r, &out);
973
1305
}
974
1306
 
 
1307
# if (nginx_version >= 1007009)
 
1308
 
 
1309
/*
 
1310
 * Based on: ngx_http_upstream.c/ngx_http_upstream_cache_get
 
1311
 * Copyright (C) Igor Sysoev
 
1312
 * Copyright (C) Nginx, Inc.
 
1313
 */
 
1314
ngx_int_t
 
1315
ngx_http_cache_purge_cache_get(ngx_http_request_t *r, ngx_http_upstream_t *u,
 
1316
    ngx_http_file_cache_t **cache)
 
1317
{
 
1318
    ngx_str_t               *name, val;
 
1319
    ngx_uint_t               i;
 
1320
    ngx_http_file_cache_t  **caches;
 
1321
 
 
1322
    if (u->conf->cache_zone) {
 
1323
        *cache = u->conf->cache_zone->data;
 
1324
        return NGX_OK;
 
1325
    }
 
1326
 
 
1327
    if (ngx_http_complex_value(r, u->conf->cache_value, &val) != NGX_OK) {
 
1328
        return NGX_ERROR;
 
1329
    }
 
1330
 
 
1331
    if (val.len == 0
 
1332
        || (val.len == 3 && ngx_strncmp(val.data, "off", 3) == 0))
 
1333
    {
 
1334
        return NGX_DECLINED;
 
1335
    }
 
1336
 
 
1337
    caches = u->caches->elts;
 
1338
 
 
1339
    for (i = 0; i < u->caches->nelts; i++) {
 
1340
        name = &caches[i]->shm_zone->shm.name;
 
1341
 
 
1342
        if (name->len == val.len
 
1343
            && ngx_strncmp(name->data, val.data, val.len) == 0)
 
1344
        {
 
1345
            *cache = caches[i];
 
1346
            return NGX_OK;
 
1347
        }
 
1348
    }
 
1349
 
 
1350
    ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
 
1351
                  "cache \"%V\" not found", &val);
 
1352
 
 
1353
    return NGX_ERROR;
 
1354
}
 
1355
 
 
1356
# endif /* nginx_version >= 1007009 */
 
1357
 
975
1358
ngx_int_t
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)