comparison src/http/modules/ngx_http_proxy_module.c @ 7786:529b73f75d19

Proxy: variables support in "proxy_cookie_flags" flags.
author Ruslan Ermilov <ru@nginx.com>
date Tue, 02 Mar 2021 00:58:24 +0300
parents 83c4622053b0
children 7ce28b4cc57e
comparison
equal deleted inserted replaced
7785:c43a2e8fdf7e 7786:529b73f75d19
54 #if (NGX_PCRE) 54 #if (NGX_PCRE)
55 ngx_http_regex_t *regex; 55 ngx_http_regex_t *regex;
56 #endif 56 #endif
57 } cookie; 57 } cookie;
58 58
59 ngx_uint_t flags; 59 ngx_array_t flags_values;
60 ngx_uint_t regex; 60 ngx_uint_t regex;
61 } ngx_http_proxy_cookie_flags_t; 61 } ngx_http_proxy_cookie_flags_t;
62 62
63 63
64 typedef struct { 64 typedef struct {
2914 2914
2915 static ngx_int_t 2915 static ngx_int_t
2916 ngx_http_proxy_rewrite_cookie_flags(ngx_http_request_t *r, ngx_array_t *attrs, 2916 ngx_http_proxy_rewrite_cookie_flags(ngx_http_request_t *r, ngx_array_t *attrs,
2917 ngx_array_t *flags) 2917 ngx_array_t *flags)
2918 { 2918 {
2919 ngx_str_t pattern; 2919 ngx_str_t pattern, value;
2920 #if (NGX_PCRE) 2920 #if (NGX_PCRE)
2921 ngx_int_t rc; 2921 ngx_int_t rc;
2922 #endif 2922 #endif
2923 ngx_uint_t i; 2923 ngx_uint_t i, m, f, nelts;
2924 ngx_keyval_t *attr; 2924 ngx_keyval_t *attr;
2925 ngx_conf_bitmask_t *mask;
2926 ngx_http_complex_value_t *flags_values;
2925 ngx_http_proxy_cookie_flags_t *pcf; 2927 ngx_http_proxy_cookie_flags_t *pcf;
2926 2928
2927 attr = attrs->elts; 2929 attr = attrs->elts;
2928 pcf = flags->elts; 2930 pcf = flags->elts;
2929 2931
2963 2965
2964 if (i == flags->nelts) { 2966 if (i == flags->nelts) {
2965 return NGX_DECLINED; 2967 return NGX_DECLINED;
2966 } 2968 }
2967 2969
2968 return ngx_http_proxy_edit_cookie_flags(r, attrs, pcf[i].flags); 2970 nelts = pcf[i].flags_values.nelts;
2971 flags_values = pcf[i].flags_values.elts;
2972
2973 mask = ngx_http_proxy_cookie_flags_masks;
2974 f = 0;
2975
2976 for (i = 0; i < nelts; i++) {
2977
2978 if (ngx_http_complex_value(r, &flags_values[i], &value) != NGX_OK) {
2979 return NGX_ERROR;
2980 }
2981
2982 if (value.len == 0) {
2983 continue;
2984 }
2985
2986 for (m = 0; mask[m].name.len != 0; m++) {
2987
2988 if (mask[m].name.len != value.len
2989 || ngx_strncasecmp(mask[m].name.data, value.data, value.len)
2990 != 0)
2991 {
2992 continue;
2993 }
2994
2995 f |= mask[m].mask;
2996
2997 break;
2998 }
2999
3000 if (mask[m].name.len == 0) {
3001 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
3002 "invalid proxy_cookie_flags flag \"%V\"", &value);
3003 }
3004 }
3005
3006 if (f == 0) {
3007 return NGX_DECLINED;
3008 }
3009
3010 return ngx_http_proxy_edit_cookie_flags(r, attrs, f);
2969 } 3011 }
2970 3012
2971 3013
2972 static ngx_int_t 3014 static ngx_int_t
2973 ngx_http_proxy_edit_cookie_flags(ngx_http_request_t *r, ngx_array_t *attrs, 3015 ngx_http_proxy_edit_cookie_flags(ngx_http_request_t *r, ngx_array_t *attrs,
4512 ngx_http_proxy_cookie_flags(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 4554 ngx_http_proxy_cookie_flags(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
4513 { 4555 {
4514 ngx_http_proxy_loc_conf_t *plcf = conf; 4556 ngx_http_proxy_loc_conf_t *plcf = conf;
4515 4557
4516 ngx_str_t *value; 4558 ngx_str_t *value;
4517 ngx_uint_t i, m; 4559 ngx_uint_t i;
4518 ngx_conf_bitmask_t *mask; 4560 ngx_http_complex_value_t *cv;
4519 ngx_http_proxy_cookie_flags_t *pcf; 4561 ngx_http_proxy_cookie_flags_t *pcf;
4520 ngx_http_compile_complex_value_t ccv; 4562 ngx_http_compile_complex_value_t ccv;
4521 #if (NGX_PCRE) 4563 #if (NGX_PCRE)
4522 ngx_regex_compile_t rc; 4564 ngx_regex_compile_t rc;
4523 u_char errstr[NGX_MAX_CONF_ERRSTR]; 4565 u_char errstr[NGX_MAX_CONF_ERRSTR];
4597 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) { 4639 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
4598 return NGX_CONF_ERROR; 4640 return NGX_CONF_ERROR;
4599 } 4641 }
4600 } 4642 }
4601 4643
4602 mask = ngx_http_proxy_cookie_flags_masks; 4644 if (ngx_array_init(&pcf->flags_values, cf->pool, cf->args->nelts - 2,
4603 pcf->flags = 0; 4645 sizeof(ngx_http_complex_value_t))
4646 != NGX_OK)
4647 {
4648 return NGX_CONF_ERROR;
4649 }
4604 4650
4605 for (i = 2; i < cf->args->nelts; i++) { 4651 for (i = 2; i < cf->args->nelts; i++) {
4606 for (m = 0; mask[m].name.len != 0; m++) { 4652
4607 4653 cv = ngx_array_push(&pcf->flags_values);
4608 if (mask[m].name.len != value[i].len 4654 if (cv == NULL) {
4609 || ngx_strcasecmp(mask[m].name.data, value[i].data) != 0) 4655 return NGX_CONF_ERROR;
4610 { 4656 }
4611 continue; 4657
4612 } 4658 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
4613 4659
4614 if (pcf->flags & mask[m].mask) { 4660 ccv.cf = cf;
4615 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, 4661 ccv.value = &value[i];
4616 "duplicate parameter \"%V\"", &value[i]); 4662 ccv.complex_value = cv;
4617 return NGX_CONF_ERROR; 4663
4618 } 4664 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
4619
4620 pcf->flags |= mask[m].mask;
4621
4622 break;
4623 }
4624
4625 if (mask[m].name.len == 0) {
4626 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
4627 "invalid parameter \"%V\"", &value[i]);
4628 return NGX_CONF_ERROR; 4665 return NGX_CONF_ERROR;
4629 } 4666 }
4630 } 4667 }
4631 4668
4632 return NGX_CONF_OK; 4669 return NGX_CONF_OK;