Permalink
Browse files

now we only register our filters when rds_json is actually used in ng…

…inx.conf.
  • Loading branch information...
1 parent 8df7b6c commit 8393c87f1ee758e066051ef691618cf08394b487 @agentzh agentzh committed Sep 20, 2011
Showing with 31 additions and 6 deletions.
  1. +31 −6 src/ngx_http_rds_json_filter_module.c
@@ -18,6 +18,9 @@
#define ngx_http_rds_json_content_type "application/json"
+
+static unsigned ngx_http_rds_json_filter_used = 0;
+
static ngx_conf_enum_t ngx_http_rds_json_formats[] = {
{ ngx_string("normal"), json_format_normal },
{ ngx_string("compact"), json_format_compact },
@@ -42,6 +45,8 @@ static char * ngx_http_rds_json_success_property(ngx_conf_t *cf,
ngx_command_t *cmd, void *conf);
static char * ngx_http_rds_json_user_property(ngx_conf_t *cf,
ngx_command_t *cmd, void *conf);
+static char * ngx_http_rds_json(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
+static ngx_int_t ngx_http_rds_json_pre_config(ngx_conf_t *cf);
static ngx_command_t ngx_http_rds_json_commands[] = {
@@ -50,7 +55,7 @@ static ngx_command_t ngx_http_rds_json_commands[] = {
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
|NGX_CONF_FLAG,
- ngx_conf_set_flag_slot,
+ ngx_http_rds_json,
NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_rds_json_conf_t, enabled),
NULL },
@@ -120,7 +125,7 @@ static ngx_command_t ngx_http_rds_json_commands[] = {
static ngx_http_module_t ngx_http_rds_json_filter_module_ctx = {
- NULL, /* preconfiguration */
+ ngx_http_rds_json_pre_config, /* preconfiguration */
ngx_http_rds_json_filter_init, /* postconfiguration */
NULL, /* create main configuration */
@@ -318,11 +323,14 @@ static ngx_int_t
ngx_http_rds_json_filter_init(ngx_conf_t *cf)
{
dd("setting next filter");
- ngx_http_rds_json_next_header_filter = ngx_http_top_header_filter;
- ngx_http_top_header_filter = ngx_http_rds_json_header_filter;
- ngx_http_rds_json_next_body_filter = ngx_http_top_body_filter;
- ngx_http_top_body_filter = ngx_http_rds_json_body_filter;
+ if (ngx_http_rds_json_filter_used) {
+ ngx_http_rds_json_next_header_filter = ngx_http_top_header_filter;
+ ngx_http_top_header_filter = ngx_http_rds_json_header_filter;
+
+ ngx_http_rds_json_next_body_filter = ngx_http_top_body_filter;
+ ngx_http_top_body_filter = ngx_http_rds_json_body_filter;
+ }
return NGX_OK;
}
@@ -644,3 +652,20 @@ ngx_http_rds_json_user_property(ngx_conf_t *cf, ngx_command_t *cmd,
return NGX_CONF_OK;
}
+
+static char *
+ngx_http_rds_json(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
+{
+ ngx_http_rds_json_filter_used = 1;
+
+ return ngx_conf_set_flag_slot(cf, cmd, conf);
+}
+
+
+static ngx_int_t ngx_http_rds_json_pre_config(ngx_conf_t *cf)
+{
+ ngx_http_rds_json_filter_used = 0;
+
+ return NGX_OK;
+}
+

0 comments on commit 8393c87

Please sign in to comment.