comparison src/http/ngx_http_upstream.c @ 6793:0fba3ed4e7eb

Cache: proxy_cache_max_range_offset and friends. It configures a threshold in bytes, above which client range requests are not cached. In such a case the client's Range header is passed directly to a proxied server.
author Dmitry Volyntsev <xeioex@nginx.com>
date Wed, 02 Nov 2016 20:05:21 +0300
parents 4dea01cf49e8
children 93b294c5d581
comparison
equal deleted inserted replaced
6792:45d553812055 6793:0fba3ed4e7eb
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, 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); 17 ngx_http_upstream_t *u, ngx_http_file_cache_t **cache);
18 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,
19 ngx_http_upstream_t *u);
20 static ngx_int_t ngx_http_upstream_cache_check_range(ngx_http_request_t *r,
19 ngx_http_upstream_t *u); 21 ngx_http_upstream_t *u);
20 static ngx_int_t ngx_http_upstream_cache_status(ngx_http_request_t *r, 22 static ngx_int_t ngx_http_upstream_cache_status(ngx_http_request_t *r,
21 ngx_http_variable_value_t *v, uintptr_t data); 23 ngx_http_variable_value_t *v, uintptr_t data);
22 static ngx_int_t ngx_http_upstream_cache_last_modified(ngx_http_request_t *r, 24 static ngx_int_t ngx_http_upstream_cache_last_modified(ngx_http_request_t *r,
23 ngx_http_variable_value_t *v, uintptr_t data); 25 ngx_http_variable_value_t *v, uintptr_t data);
920 u->cache_status = NGX_HTTP_CACHE_HIT; 922 u->cache_status = NGX_HTTP_CACHE_HIT;
921 923
922 return rc; 924 return rc;
923 } 925 }
924 926
927 if (ngx_http_upstream_cache_check_range(r, u) == NGX_DECLINED) {
928 u->cacheable = 0;
929 }
930
925 r->cached = 0; 931 r->cached = 0;
926 932
927 return NGX_DECLINED; 933 return NGX_DECLINED;
928 } 934 }
929 935
1019 /* rc == NGX_HTTP_UPSTREAM_INVALID_HEADER */ 1025 /* rc == NGX_HTTP_UPSTREAM_INVALID_HEADER */
1020 1026
1021 /* TODO: delete file */ 1027 /* TODO: delete file */
1022 1028
1023 return rc; 1029 return rc;
1030 }
1031
1032
1033 static ngx_int_t
1034 ngx_http_upstream_cache_check_range(ngx_http_request_t *r,
1035 ngx_http_upstream_t *u)
1036 {
1037 off_t offset;
1038 u_char *p, *start;
1039 ngx_table_elt_t *h;
1040
1041 h = r->headers_in.range;
1042
1043 if (h == NULL
1044 || !u->cacheable
1045 || u->conf->cache_max_range_offset == NGX_MAX_OFF_T_VALUE)
1046 {
1047 return NGX_OK;
1048 }
1049
1050 if (u->conf->cache_max_range_offset == 0) {
1051 return NGX_DECLINED;
1052 }
1053
1054 if (h->value.len < 7
1055 || ngx_strncasecmp(h->value.data, (u_char *) "bytes=", 6) != 0)
1056 {
1057 return NGX_OK;
1058 }
1059
1060 p = h->value.data + 6;
1061
1062 while (*p == ' ') { p++; }
1063
1064 if (*p == '-') {
1065 return NGX_DECLINED;
1066 }
1067
1068 start = p;
1069
1070 while (*p >= '0' && *p <= '9') { p++; }
1071
1072 offset = ngx_atoof(start, p - start);
1073
1074 if (offset >= u->conf->cache_max_range_offset) {
1075 return NGX_DECLINED;
1076 }
1077
1078 return NGX_OK;
1024 } 1079 }
1025 1080
1026 #endif 1081 #endif
1027 1082
1028 1083