Mercurial > hg > nginx-vendor-current
comparison src/http/modules/ngx_http_rewrite_module.c @ 64:5db440287648 NGINX_0_1_32
nginx 0.1.32
*) Bugfix: the arguments were omitted in the redirects, issued by the
"rewrite" directive; bug appeared in 0.1.29.
*) Feature: the "if" directive supports the captures in regular
expressions.
*) Feature: the "set" directive supports the variables and the captures
of regular expressions.
*) Feature: the "X-Accel-Redirect" response header line is supported in
proxy and FastCGI mode.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Thu, 19 May 2005 00:00:00 +0400 |
parents | b55cbf18157e |
children | 818201e5a553 |
comparison
equal
deleted
inserted
replaced
63:e42867135781 | 64:5db440287648 |
---|---|
14 ngx_uint_t wildcard; | 14 ngx_uint_t wildcard; |
15 } ngx_http_rewrite_referer_t; | 15 } ngx_http_rewrite_referer_t; |
16 | 16 |
17 | 17 |
18 typedef struct { | 18 typedef struct { |
19 ngx_str_t *name; | |
20 ngx_http_variable_value_t *value; | |
21 } ngx_http_rewrite_variable_t; | |
22 | |
23 | |
24 typedef struct { | |
25 ngx_array_t *codes; /* uintptr_t */ | 19 ngx_array_t *codes; /* uintptr_t */ |
26 ngx_array_t *referers; /* ngx_http_rewrite_referer_t */ | 20 ngx_array_t *referers; /* ngx_http_rewrite_referer_t */ |
27 | 21 |
28 ngx_uint_t max_captures; | 22 ngx_uint_t captures; |
29 ngx_uint_t stack_size; | 23 ngx_uint_t stack_size; |
30 | 24 |
31 ngx_flag_t log; | 25 ngx_flag_t log; |
32 | 26 |
33 ngx_flag_t no_referer; | 27 ngx_flag_t no_referer; |
157 cf->stack_size * sizeof(ngx_http_variable_value_t)); | 151 cf->stack_size * sizeof(ngx_http_variable_value_t)); |
158 if (e->sp == NULL) { | 152 if (e->sp == NULL) { |
159 return NGX_HTTP_INTERNAL_SERVER_ERROR; | 153 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
160 } | 154 } |
161 | 155 |
162 if (cf->max_captures) { | 156 if (cf->captures) { |
163 e->captures = ngx_palloc(r->pool, cf->max_captures * sizeof(int)); | 157 e->captures = ngx_palloc(r->pool, cf->captures * sizeof(int)); |
164 if (e->captures == NULL) { | 158 if (e->captures == NULL) { |
165 return NGX_HTTP_INTERNAL_SERVER_ERROR; | 159 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
166 } | 160 } |
167 | 161 |
168 } else { | 162 } else { |
540 regex->ncaptures = (ngx_uint_t) n; | 534 regex->ncaptures = (ngx_uint_t) n; |
541 } | 535 } |
542 | 536 |
543 if (regex->ncaptures) { | 537 if (regex->ncaptures) { |
544 regex->ncaptures = (regex->ncaptures + 1) * 3; | 538 regex->ncaptures = (regex->ncaptures + 1) * 3; |
545 } | 539 |
546 | 540 if (lcf->captures < regex->ncaptures) { |
547 if (lcf->max_captures < regex->ncaptures) { | 541 lcf->captures = regex->ncaptures; |
548 lcf->max_captures = regex->ncaptures; | 542 } |
549 } | 543 } |
550 | 544 |
551 regex_end = ngx_http_script_add_code(lcf->codes, | 545 regex_end = ngx_http_script_add_code(lcf->codes, |
552 sizeof(ngx_http_script_regex_end_code_t), | 546 sizeof(ngx_http_script_regex_end_code_t), |
553 ®ex); | 547 ®ex); |
733 | 727 |
734 static char * | 728 static char * |
735 ngx_http_rewrite_if_condition(ngx_conf_t *cf, ngx_http_rewrite_loc_conf_t *lcf) | 729 ngx_http_rewrite_if_condition(ngx_conf_t *cf, ngx_http_rewrite_loc_conf_t *lcf) |
736 { | 730 { |
737 ngx_str_t *value, err; | 731 ngx_str_t *value, err; |
738 ngx_uint_t cur, last; | 732 ngx_uint_t cur, last, n; |
739 ngx_http_script_regex_code_t *regex; | 733 ngx_http_script_regex_code_t *regex; |
740 u_char errstr[NGX_MAX_CONF_ERRSTR]; | 734 u_char errstr[NGX_MAX_CONF_ERRSTR]; |
741 | 735 |
742 value = cf->args->elts; | 736 value = cf->args->elts; |
743 last = cf->args->nelts - 1; | 737 last = cf->args->nelts - 1; |
820 | 814 |
821 regex->code = ngx_http_script_regex_start_code; | 815 regex->code = ngx_http_script_regex_start_code; |
822 regex->next = sizeof(ngx_http_script_regex_code_t); | 816 regex->next = sizeof(ngx_http_script_regex_code_t); |
823 regex->test = 1; | 817 regex->test = 1; |
824 regex->name = value[last]; | 818 regex->name = value[last]; |
819 | |
820 n = ngx_regex_capture_count(regex->regex); | |
821 | |
822 if (n) { | |
823 regex->ncaptures = (n + 1) * 3; | |
824 | |
825 if (lcf->captures < regex->ncaptures) { | |
826 lcf->captures = regex->ncaptures; | |
827 } | |
828 } | |
825 | 829 |
826 return NGX_CONF_OK; | 830 return NGX_CONF_OK; |
827 } | 831 } |
828 | 832 |
829 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 833 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
975 static char * | 979 static char * |
976 ngx_http_rewrite_set(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 980 ngx_http_rewrite_set(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
977 { | 981 { |
978 ngx_http_rewrite_loc_conf_t *lcf = conf; | 982 ngx_http_rewrite_loc_conf_t *lcf = conf; |
979 | 983 |
980 ngx_int_t n, index; | 984 ngx_int_t n, index; |
981 ngx_str_t *value; | 985 ngx_str_t *value; |
982 ngx_http_variable_t *v; | 986 ngx_http_variable_t *v; |
983 ngx_http_script_var_code_t *var; | 987 ngx_http_script_compile_t sc; |
984 ngx_http_script_value_code_t *val; | 988 ngx_http_script_var_code_t *var; |
989 ngx_http_script_value_code_t *val; | |
990 ngx_http_script_complex_value_code_t *complex; | |
985 | 991 |
986 value = cf->args->elts; | 992 value = cf->args->elts; |
987 | 993 |
988 if (value[1].data[0] != '$') { | 994 if (value[1].data[0] != '$') { |
989 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 995 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
1005 } | 1011 } |
1006 | 1012 |
1007 v->handler = ngx_http_rewrite_var; | 1013 v->handler = ngx_http_rewrite_var; |
1008 v->data = index; | 1014 v->data = index; |
1009 | 1015 |
1010 val = ngx_http_script_start_code(cf->pool, &lcf->codes, | 1016 n = ngx_http_script_variables_count(&value[2]); |
1011 sizeof(ngx_http_script_value_code_t)); | 1017 |
1012 if (val == NULL) { | 1018 if (n == 0) { |
1013 return NGX_CONF_ERROR; | 1019 val = ngx_http_script_start_code(cf->pool, &lcf->codes, |
1014 } | 1020 sizeof(ngx_http_script_value_code_t)); |
1015 | 1021 if (val == NULL) { |
1016 n = ngx_atoi(value[2].data, value[2].len); | 1022 return NGX_CONF_ERROR; |
1017 | 1023 } |
1018 if (n == NGX_ERROR) { | 1024 |
1019 n = 0; | 1025 n = ngx_atoi(value[2].data, value[2].len); |
1020 } | 1026 |
1021 | 1027 if (n == NGX_ERROR) { |
1022 val->code = ngx_http_script_value_code; | 1028 n = 0; |
1023 val->value = (uintptr_t) n; | 1029 } |
1024 val->text_len = (uintptr_t) value[2].len; | 1030 |
1025 val->text_data = (uintptr_t) value[2].data; | 1031 val->code = ngx_http_script_value_code; |
1032 val->value = (uintptr_t) n; | |
1033 val->text_len = (uintptr_t) value[2].len; | |
1034 val->text_data = (uintptr_t) value[2].data; | |
1035 | |
1036 } else { | |
1037 complex = ngx_http_script_start_code(cf->pool, &lcf->codes, | |
1038 sizeof(ngx_http_script_complex_value_code_t)); | |
1039 if (complex == NULL) { | |
1040 return NGX_CONF_ERROR; | |
1041 } | |
1042 | |
1043 complex->code = ngx_http_script_complex_value_code; | |
1044 complex->lengths = NULL; | |
1045 | |
1046 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); | |
1047 | |
1048 sc.cf = cf; | |
1049 sc.source = &value[2]; | |
1050 sc.lengths = &complex->lengths; | |
1051 sc.values = &lcf->codes; | |
1052 sc.variables = n; | |
1053 sc.complete_lengths = 1; | |
1054 | |
1055 if (ngx_http_script_compile(&sc) != NGX_OK) { | |
1056 return NGX_CONF_ERROR; | |
1057 } | |
1058 } | |
1026 | 1059 |
1027 var = ngx_http_script_start_code(cf->pool, &lcf->codes, | 1060 var = ngx_http_script_start_code(cf->pool, &lcf->codes, |
1028 sizeof(ngx_http_script_var_code_t)); | 1061 sizeof(ngx_http_script_var_code_t)); |
1029 if (var == NULL) { | 1062 if (var == NULL) { |
1030 return NGX_CONF_ERROR; | 1063 return NGX_CONF_ERROR; |