Mercurial > hg > nginx-quic
comparison src/http/ngx_http_upstream.c @ 5951:610832763648
Upstream: added variables support to proxy_cache and friends.
author | Valentin Bartenev <vbart@nginx.com> |
---|---|
date | Mon, 22 Dec 2014 12:59:09 +0300 |
parents | eaeecf00d5d7 |
children | f7584d7c0ccb |
comparison
equal
deleted
inserted
replaced
5950:eaeecf00d5d7 | 5951:610832763648 |
---|---|
11 | 11 |
12 | 12 |
13 #if (NGX_HTTP_CACHE) | 13 #if (NGX_HTTP_CACHE) |
14 static ngx_int_t ngx_http_upstream_cache(ngx_http_request_t *r, | 14 static ngx_int_t ngx_http_upstream_cache(ngx_http_request_t *r, |
15 ngx_http_upstream_t *u); | 15 ngx_http_upstream_t *u); |
16 static ngx_int_t ngx_http_upstream_cache_get(ngx_http_request_t *r, | |
17 ngx_http_upstream_t *u, ngx_http_file_cache_t **cache); | |
16 static ngx_int_t ngx_http_upstream_cache_send(ngx_http_request_t *r, | 18 static ngx_int_t ngx_http_upstream_cache_send(ngx_http_request_t *r, |
17 ngx_http_upstream_t *u); | 19 ngx_http_upstream_t *u); |
18 static ngx_int_t ngx_http_upstream_cache_status(ngx_http_request_t *r, | 20 static ngx_int_t ngx_http_upstream_cache_status(ngx_http_request_t *r, |
19 ngx_http_variable_value_t *v, uintptr_t data); | 21 ngx_http_variable_value_t *v, uintptr_t data); |
20 static ngx_int_t ngx_http_upstream_cache_last_modified(ngx_http_request_t *r, | 22 static ngx_int_t ngx_http_upstream_cache_last_modified(ngx_http_request_t *r, |
721 #if (NGX_HTTP_CACHE) | 723 #if (NGX_HTTP_CACHE) |
722 | 724 |
723 static ngx_int_t | 725 static ngx_int_t |
724 ngx_http_upstream_cache(ngx_http_request_t *r, ngx_http_upstream_t *u) | 726 ngx_http_upstream_cache(ngx_http_request_t *r, ngx_http_upstream_t *u) |
725 { | 727 { |
726 ngx_int_t rc; | 728 ngx_int_t rc; |
727 ngx_http_cache_t *c; | 729 ngx_http_cache_t *c; |
730 ngx_http_file_cache_t *cache; | |
728 | 731 |
729 c = r->cache; | 732 c = r->cache; |
730 | 733 |
731 if (c == NULL) { | 734 if (c == NULL) { |
732 | 735 |
733 if (!(r->method & u->conf->cache_methods)) { | 736 if (!(r->method & u->conf->cache_methods)) { |
734 return NGX_DECLINED; | 737 return NGX_DECLINED; |
738 } | |
739 | |
740 rc = ngx_http_upstream_cache_get(r, u, &cache); | |
741 | |
742 if (rc != NGX_OK) { | |
743 return rc; | |
735 } | 744 } |
736 | 745 |
737 if (r->method & NGX_HTTP_HEAD) { | 746 if (r->method & NGX_HTTP_HEAD) { |
738 u->method = ngx_http_core_get_method; | 747 u->method = ngx_http_core_get_method; |
739 } | 748 } |
765 | 774 |
766 c = r->cache; | 775 c = r->cache; |
767 | 776 |
768 c->body_start = u->conf->buffer_size; | 777 c->body_start = u->conf->buffer_size; |
769 c->min_uses = u->conf->cache_min_uses; | 778 c->min_uses = u->conf->cache_min_uses; |
770 c->file_cache = u->conf->cache_zone->data; | 779 c->file_cache = cache; |
771 | 780 |
772 switch (ngx_http_test_predicates(r, u->conf->cache_bypass)) { | 781 switch (ngx_http_test_predicates(r, u->conf->cache_bypass)) { |
773 | 782 |
774 case NGX_ERROR: | 783 case NGX_ERROR: |
775 return NGX_ERROR; | 784 return NGX_ERROR; |
868 } | 877 } |
869 | 878 |
870 r->cached = 0; | 879 r->cached = 0; |
871 | 880 |
872 return NGX_DECLINED; | 881 return NGX_DECLINED; |
882 } | |
883 | |
884 | |
885 static ngx_int_t | |
886 ngx_http_upstream_cache_get(ngx_http_request_t *r, ngx_http_upstream_t *u, | |
887 ngx_http_file_cache_t **cache) | |
888 { | |
889 ngx_str_t *name, val; | |
890 ngx_uint_t i; | |
891 ngx_http_file_cache_t **caches; | |
892 | |
893 if (u->conf->cache_zone) { | |
894 *cache = u->conf->cache_zone->data; | |
895 return NGX_OK; | |
896 } | |
897 | |
898 if (ngx_http_complex_value(r, u->conf->cache_value, &val) != NGX_OK) { | |
899 return NGX_ERROR; | |
900 } | |
901 | |
902 if (val.len == 0 | |
903 || (val.len == 3 && ngx_strncmp(val.data, "off", 3) == 0)) | |
904 { | |
905 return NGX_DECLINED; | |
906 } | |
907 | |
908 caches = u->caches->elts; | |
909 | |
910 for (i = 0; i < u->caches->nelts; i++) { | |
911 name = &caches[i]->shm_zone->shm.name; | |
912 | |
913 if (name->len == val.len | |
914 && ngx_strncmp(name->data, val.data, val.len) == 0) | |
915 { | |
916 *cache = caches[i]; | |
917 return NGX_OK; | |
918 } | |
919 } | |
920 | |
921 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
922 "cache \"%V\" not found", &val); | |
923 | |
924 return NGX_ERROR; | |
873 } | 925 } |
874 | 926 |
875 | 927 |
876 static ngx_int_t | 928 static ngx_int_t |
877 ngx_http_upstream_cache_send(ngx_http_request_t *r, ngx_http_upstream_t *u) | 929 ngx_http_upstream_cache_send(ngx_http_request_t *r, ngx_http_upstream_t *u) |