Browse files

fixed coding style in Matthieu Tourne's patch for adding the rewrite_…

…by_lua_no_postpone directive; also added some tests for it.
  • Loading branch information...
1 parent 436cd30 commit 46aa878051ffb3b4e16441f0f65e218261af7c9c @agentzh agentzh committed May 25, 2012
View
4 src/ngx_http_lua_common.h
@@ -84,8 +84,8 @@ typedef struct {
ngx_array_t *shm_zones; /* of ngx_shm_zone_t* */
- unsigned postponed_to_rewrite_phase_end:1;
- unsigned postponed_to_access_phase_end:1;
+ ngx_flag_t postponed_to_rewrite_phase_end;
+ ngx_flag_t postponed_to_access_phase_end;
} ngx_http_lua_main_conf_t;
View
1 src/ngx_http_lua_conf.c
@@ -37,6 +37,7 @@ ngx_http_lua_create_main_conf(ngx_conf_t *cf)
#if (NGX_PCRE)
lmcf->regex_cache_max_entries = NGX_CONF_UNSET;
#endif
+ lmcf->postponed_to_rewrite_phase_end = NGX_CONF_UNSET;
dd("nginx Lua module main config structure initialized!");
View
28 src/ngx_http_lua_directive.c
@@ -704,31 +704,3 @@ ngx_http_lua_header_filter_by_lua(ngx_conf_t *cf, ngx_command_t *cmd,
return NGX_CONF_OK;
}
-char *
-ngx_http_lua_rewrite_no_postpone(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
-{
- ngx_http_lua_main_conf_t *lmcf = conf;
- ngx_str_t *value;
- ngx_int_t fp;
-
- value = cf->args->elts;
-
-
- if (ngx_strcasecmp(value[1].data, (u_char *) "on") == 0) {
- fp = 1;
-
- } else if (ngx_strcasecmp(value[1].data, (u_char *) "off") == 0) {
- fp = 0;
-
- } else {
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "invalid value \"%s\" in \"%s\" directive, "
- "it must be \"on\" or \"off\"",
- value[1].data, cmd->name.data);
- return NGX_CONF_ERROR;
- }
-
- lmcf->postponed_to_rewrite_phase_end = fp;
-
- return NGX_CONF_OK;
-}
View
5 src/ngx_http_lua_directive.h
@@ -37,9 +37,8 @@ ngx_int_t ngx_http_lua_filter_set_by_lua_file(ngx_http_request_t *r,
ngx_str_t *val, ngx_http_variable_value_t *v, void *data);
#endif
-char * ngx_http_lua_rewrite_no_postpone(ngx_conf_t *cf,
- ngx_command_t *cmd,
- void *conf);
+char * ngx_http_lua_rewrite_no_postpone(ngx_conf_t *cf, ngx_command_t *cmd,
+ void *conf);
#endif /* NGX_HTTP_LUA_DIRECTIVE_H */
View
11 src/ngx_http_lua_module.c
@@ -137,9 +137,9 @@ static ngx_command_t ngx_http_lua_cmds[] = {
{ ngx_string("rewrite_by_lua_no_postpone"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
|NGX_CONF_FLAG,
- ngx_http_lua_rewrite_no_postpone,
+ ngx_conf_set_flag_slot,
NGX_HTTP_MAIN_CONF_OFFSET,
- 0,
+ offsetof(ngx_http_lua_main_conf_t, postponed_to_rewrite_phase_end),
NULL },
{ ngx_string("access_by_lua_file"),
@@ -270,12 +270,19 @@ ngx_http_lua_init(ngx_conf_t *cf)
ngx_int_t rc;
ngx_http_handler_pt *h;
ngx_http_core_main_conf_t *cmcf;
+ ngx_http_lua_main_conf_t *lmcf;
rc = ngx_http_lua_capture_filter_init(cf);
if (rc != NGX_OK) {
return rc;
}
+ lmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_lua_module);
+
+ if (lmcf->postponed_to_rewrite_phase_end == NGX_CONF_UNSET) {
+ lmcf->postponed_to_rewrite_phase_end = 0;
+ }
+
cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
if (ngx_http_lua_requires_rewrite) {
View
85 t/076-no-postpone.t
@@ -0,0 +1,85 @@
+# vim:set ft= ts=4 sw=4 et fdm=marker:
+use lib 'lib';
+use Test::Nginx::Socket;
+
+#worker_connections(1014);
+#master_on();
+#workers(2);
+#log_level('warn');
+
+repeat_each(2);
+#repeat_each(1);
+
+plan tests => repeat_each() * (blocks() * 3);
+
+#no_diff();
+#no_long_string();
+run_tests();
+
+__DATA__
+
+=== TEST 1: rewrite no postpone on
+--- http_config
+ rewrite_by_lua_no_postpone on;
+--- config
+ set $foo '';
+ location /t {
+ rewrite_by_lua '
+ ngx.var.foo = 1
+ ';
+ if ($foo = 1) {
+ echo "foo: $foo";
+ }
+ echo "no foo: $foo";
+ }
+--- request
+GET /t
+--- response_body
+foo: 1
+--- no_error_log
+[error]
+
+
+
+=== TEST 2: rewrite no postpone explicitly off
+--- http_config
+ rewrite_by_lua_no_postpone off;
+--- config
+ set $foo '';
+ location /t {
+ rewrite_by_lua '
+ ngx.var.foo = 1
+ ';
+ if ($foo = 1) {
+ echo "foo: $foo";
+ }
+ echo "no foo: $foo";
+ }
+--- request
+GET /t
+--- response_body
+no foo: 1
+--- no_error_log
+[error]
+
+
+
+=== TEST 3: rewrite no postpone off by default
+--- config
+ set $foo '';
+ location /t {
+ rewrite_by_lua '
+ ngx.var.foo = 1
+ ';
+ if ($foo = 1) {
+ echo "foo: $foo";
+ }
+ echo "no foo: $foo";
+ }
+--- request
+GET /t
+--- response_body
+no foo: 1
+--- no_error_log
+[error]
+

0 comments on commit 46aa878

Please sign in to comment.