Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

feature: the set_rotate directive will always make the current value …

…persistent and make use of it when either the current value is not given or the current value is invalid.
  • Loading branch information...
commit 9792e8d8691ce0a82a0290dea186b81a53feab30 1 parent 16c7b48
@agentzh agentzh authored
View
1  src/ngx_http_set_base32.h
@@ -15,3 +15,4 @@ ngx_int_t ngx_http_set_misc_decode_base32(ngx_http_request_t *r,
#endif /* NGX_HTTP_SET_BASE32 */
+
View
3  src/ngx_http_set_misc_module.c
@@ -378,6 +378,7 @@ ngx_http_set_misc_create_loc_conf(ngx_conf_t *cf)
}
conf->base32_padding = NGX_CONF_UNSET;
+ conf->current = NGX_CONF_UNSET;
return conf;
}
@@ -391,6 +392,8 @@ ngx_http_set_misc_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
ngx_conf_merge_value(conf->base32_padding, prev->base32_padding, 1);
+ ngx_conf_merge_value(conf->current, prev->current, NGX_CONF_UNSET);
+
return NGX_CONF_OK;
}
View
1  src/ngx_http_set_misc_module.h
@@ -4,6 +4,7 @@
typedef struct {
ngx_flag_t base32_padding;
+ ngx_int_t current; /* for set_rotate */
} ngx_http_set_misc_loc_conf_t;
View
36 src/ngx_http_set_rotate.c
@@ -5,6 +5,7 @@
#include <ndk.h>
#include "ngx_http_set_rotate.h"
+#include "ngx_http_set_misc_module.h"
#include <stdlib.h>
@@ -15,6 +16,8 @@ ngx_http_set_misc_set_rotate(ngx_http_request_t *r,
ngx_http_variable_value_t *rotate_from, *rotate_to, *rotate_num;
ngx_int_t int_from, int_to, tmp, int_current;
+ ngx_http_set_misc_loc_conf_t *conf;
+
rotate_num = &v[0];
rotate_from = &v[1];
rotate_to = &v[2];
@@ -41,11 +44,32 @@ ngx_http_set_misc_set_rotate(ngx_http_request_t *r,
int_to = tmp;
}
- int_current = ngx_atoi(rotate_num->data, rotate_num->len);
- if (int_current == NGX_ERROR) {
- ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
- "set_rotate: bad current value: \"%v\"", rotate_num);
- int_current = int_from;
+ conf = ngx_http_get_module_loc_conf(r, ngx_http_set_misc_module);
+
+ dd("current value not found: %d", (int) rotate_num->not_found);
+
+ if (rotate_num->len == 0) {
+ if (conf->current != NGX_CONF_UNSET) {
+ int_current = conf->current;
+
+ } else {
+ int_current = int_from - 1;
+ }
+
+ } else {
+
+ int_current = ngx_atoi(rotate_num->data, rotate_num->len);
+ if (int_current == NGX_ERROR) {
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
+ "set_rotate: bad current value: \"%v\"", rotate_num);
+
+ if (conf->current != NGX_CONF_UNSET) {
+ int_current = conf->current;
+
+ } else {
+ int_current = int_from - 1;
+ }
+ }
}
int_current++;
@@ -54,6 +78,8 @@ ngx_http_set_misc_set_rotate(ngx_http_request_t *r,
int_current = int_from;
}
+ conf->current = int_current;
+
res->data = ngx_palloc(r->pool, NGX_INT_T_LEN);
if (res->data == NULL) {
return NGX_ERROR;
View
125 t/rotate.t
@@ -61,8 +61,7 @@ e = 3
}
--- request
GET /bar
---- response_body
-a = 2
+--- response_body_like: ^a = [12]$
--- error_log
set_rotate: bad current value: "abc"
@@ -100,3 +99,125 @@ set_rotate: bad "from" argument value: "abc"
--- error_log
set_rotate: bad "to" argument value: "abc"
+
+
+=== TEST 5: when no current value is given
+--- config
+ location /incr {
+ set_rotate $a 1 3;
+
+ echo "a = $a";
+ }
+
+ location /t {
+ echo_location /incr;
+ echo_location /incr;
+ echo_location /incr;
+ echo_location /incr;
+ echo_location /incr;
+ echo_location /incr;
+ }
+--- request
+ GET /t
+--- response_body
+a = 1
+a = 2
+a = 3
+a = 1
+a = 2
+a = 3
+--- no_error_log
+[error]
+
+
+
+=== TEST 6: when no current value is given (starting from 0)
+--- config
+ location /incr {
+ set_rotate $a 0 2;
+
+ echo "a = $a";
+ }
+
+ location /t {
+ echo_location /incr;
+ echo_location /incr;
+ echo_location /incr;
+ echo_location /incr;
+ echo_location /incr;
+ echo_location /incr;
+ }
+--- request
+ GET /t
+--- response_body
+a = 0
+a = 1
+a = 2
+a = 0
+a = 1
+a = 2
+--- no_error_log
+[error]
+
+
+
+=== TEST 7: when a non-integer string value is given
+--- config
+ location /incr {
+ set $a "hello";
+ set_rotate $a 0 2;
+
+ echo "a = $a";
+ }
+
+ location /t {
+ echo_location /incr;
+ echo_location /incr;
+ echo_location /incr;
+ echo_location /incr;
+ echo_location /incr;
+ echo_location /incr;
+ }
+--- request
+ GET /t
+--- response_body
+a = 0
+a = 1
+a = 2
+a = 0
+a = 1
+a = 2
+--- error_log
+set_rotate: bad current value: "hello"
+
+
+
+=== TEST 8: when an empty string value is given
+--- config
+ location /incr {
+ set $a "";
+ set_rotate $a 0 2;
+
+ echo "a = $a";
+ }
+
+ location /t {
+ echo_location /incr;
+ echo_location /incr;
+ echo_location /incr;
+ echo_location /incr;
+ echo_location /incr;
+ echo_location /incr;
+ }
+--- request
+ GET /t
+--- response_body
+a = 0
+a = 1
+a = 2
+a = 0
+a = 1
+a = 2
+--- no_error_log
+[error]
+
View
2  util/build.sh
@@ -7,6 +7,8 @@ home=~
version=$1
force=$2
+ #--with-cc="gcc46" \
+
ngx-build $force $version \
--with-http_ssl_module \
--without-mail_pop3_module \
Please sign in to comment.
Something went wrong with that request. Please try again.