Permalink
Browse files

fixed coding style issues at various places; bugfix: rds_json_errcode…

…_key could not be used after rds_json_root; added a failing test for using rds_json_errcode_key and/or rds_json_errstr_key with real RDS streams from ngx_drizzle.
  • Loading branch information...
1 parent 5f29b7c commit 25a5efc53d7f2bbad14e870345f10f2fa98ec528 @agentzh agentzh committed May 22, 2012
Showing with 161 additions and 120 deletions.
  1. +10 −12 src/ngx_http_rds_json_filter_module.c
  2. +2 −6 src/ngx_http_rds_json_handler.c
  3. +149 −0 t/property.t
  4. +0 −102 t/ret.t
View
22 src/ngx_http_rds_json_filter_module.c
@@ -427,11 +427,9 @@ ngx_http_rds_json_merge_conf(ngx_conf_t *cf, void *parent, void *child)
ngx_conf_merge_uint_value(conf->format, prev->format, json_format_normal);
- ngx_conf_merge_str_value(conf->root, prev->root,
- "");
+ ngx_conf_merge_str_value(conf->root, prev->root, "");
- ngx_conf_merge_str_value(conf->success, prev->success,
- "");
+ ngx_conf_merge_str_value(conf->success, prev->success, "");
if (conf->user_props == NULL) {
conf->user_props = prev->user_props;
@@ -442,16 +440,16 @@ ngx_http_rds_json_merge_conf(ngx_conf_t *cf, void *parent, void *child)
}
ngx_conf_merge_str_value(conf->errcode_key, prev->errcode_key,
- "\"errcode\"");
+ "\"errcode\"");
ngx_conf_merge_str_value(conf->errstr_key, prev->errstr_key,
- "\"errstr\"");
+ "\"errstr\"");
ngx_conf_merge_str_value(conf->content_type, prev->content_type,
- ngx_http_rds_json_content_type);
+ ngx_http_rds_json_content_type);
ngx_conf_merge_size_value(conf->buf_size, prev->buf_size,
- (size_t) ngx_pagesize);
+ (size_t) ngx_pagesize);
return NGX_CONF_OK;
}
@@ -717,7 +715,7 @@ ngx_http_rds_json_errcode_key(ngx_conf_t *cf, ngx_command_t *cmd,
value = cf->args->elts;
- if (jlcf->root.len) {
+ if (jlcf->errcode_key.len) {
return "is duplicate";
}
@@ -744,7 +742,7 @@ ngx_http_rds_json_errcode_key(ngx_conf_t *cf, ngx_command_t *cmd,
} else {
p = (u_char *) ngx_http_rds_json_escape_json_str(p, value[1].data,
- value[1].len);
+ value[1].len);
}
*p++ = '"';
@@ -777,7 +775,7 @@ ngx_http_rds_json_errstr_key(ngx_conf_t *cf, ngx_command_t *cmd,
}
escape = ngx_http_rds_json_escape_json_str(NULL, value[1].data,
- value[1].len);
+ value[1].len);
jlcf->errstr_key.len = value[1].len + escape + sizeof("\"\"") - 1;
@@ -795,7 +793,7 @@ ngx_http_rds_json_errstr_key(ngx_conf_t *cf, ngx_command_t *cmd,
} else {
p = (u_char *) ngx_http_rds_json_escape_json_str(p, value[1].data,
- value[1].len);
+ value[1].len);
}
*p++ = '"';
View
8 src/ngx_http_rds_json_handler.c
@@ -35,22 +35,18 @@ ngx_http_rds_json_ret_handler(ngx_http_request_t *r)
/* calculate the buffer size */
- len = sizeof("{") - 1
+ len = sizeof("{:}") - 1
+ conf->errcode_key.len
- + sizeof(":") - 1
+ conf->errcode.len
- + sizeof("}") - 1
;
if (errstr.len) {
escape = ngx_http_rds_json_escape_json_str(NULL,
errstr.data, errstr.len);
- len += sizeof(",") - 1
+ len += sizeof(",:\"\"") - 1
+ conf->errstr_key.len
- + sizeof(":\"") - 1
+ errstr.len + escape
- + sizeof("\"") - 1
;
}
View
149 t/property.t
@@ -387,3 +387,152 @@ GET /ret
--- response_body chomp
{"errcode":400,"errstr":"Non zero ret","city":"beijing","\"hi\"":"\"hello\n\""}
+
+
+=== TEST 21: location internal rewrite
+--- config
+ location @err403 {
+ rds_json_success_property ret;
+ rds_json_ret 403 "Forbidden";
+ }
+
+ location /foo {
+ error_page 403 = @err403;
+ return 403;
+ }
+--- request
+ GET /foo
+--- response_body chop
+{"errcode":403,"errstr":"Forbidden","ret":false}
+
+
+
+=== TEST 22: rds_json_errcode_key
+--- config
+ location /foo {
+ rds_json_errcode_key "ecode";
+ rds_json_success_property ret;
+ rds_json_ret 403 "Forbidden";
+ }
+--- request
+ GET /foo
+--- response_body chop
+{"ecode":403,"errstr":"Forbidden","ret":false}
+
+
+
+=== TEST 23: rds_json_errcode_key
+--- config
+ rds_json_errcode_key "ecoderoot";
+
+ location /foo {
+ rds_json_success_property ret;
+ rds_json_ret 403 "Forbidden";
+ }
+--- request
+ GET /foo
+--- response_body chop
+{"ecoderoot":403,"errstr":"Forbidden","ret":false}
+
+
+
+=== TEST 24: rds_json_errcode_key
+--- config
+ rds_json_errcode_key "ecoderoot";
+
+ location /foo {
+ rds_json_errcode_key "ecode";
+ rds_json_success_property ret;
+ rds_json_ret 403 "Forbidden";
+ }
+--- request
+ GET /foo
+--- response_body chop
+{"ecode":403,"errstr":"Forbidden","ret":false}
+
+
+
+=== TEST 25: rds_json_errstr_key
+--- config
+ rds_json_errstr_key "msg";
+
+ location /foo {
+ rds_json_success_property ret;
+ rds_json_ret 403 "Forbidden";
+ }
+--- request
+ GET /foo
+--- response_body chop
+{"errcode":403,"msg":"Forbidden","ret":false}
+
+
+
+=== TEST 26: rds_json_errstr_key
+--- config
+ rds_json_errstr_key "msg";
+
+ location /foo {
+ rds_json_errstr_key "msg2";
+ rds_json_success_property ret;
+ rds_json_ret 403 "Forbidden";
+ }
+--- request
+ GET /foo
+--- response_body chop
+{"errcode":403,"msg2":"Forbidden","ret":false}
+
+
+
+=== TEST 27: rds_json_errstr_key & rds_json_root
+--- config
+ rds_json_errstr_key "msg2";
+ rds_json_root rows;
+
+ location /foo {
+ rds_json_success_property ret;
+ rds_json_ret 403 "Forbidden";
+ }
+--- request
+ GET /foo
+--- response_body chop
+{"errcode":403,"msg2":"Forbidden","ret":false}
+
+
+
+=== TEST 28: rds_json_errcode_key & rds_json_root
+--- config
+ rds_json_root rows;
+ rds_json_errcode_key "code";
+
+ location /foo {
+ rds_json_success_property ret;
+ rds_json_ret 403 "Forbidden";
+ }
+--- request
+ GET /foo
+--- response_body chop
+{"code":403,"errstr":"Forbidden","ret":false}
+
+
+
+=== TEST 29: update - custom errstr_key
+--- http_config eval: $::http_config
+--- config
+ location /mysql {
+ drizzle_pass backend;
+ #drizzle_dbname $dbname;
+ drizzle_query "update cats set name='bob' where name='bob'";
+ rds_json on;
+ rds_json_errcode_key "\"code\"";
+ rds_json_errstr_key "\"str\"";
+
+ set $name 'Jimmy"';
+ set $age 32;
+ rds_json_user_property name $name;
+ rds_json_user_property age $age;
+ }
+--- request
+GET /mysql
+--- response_body chop
+{"name":"Jimmy\"","age":"32","\"code\"":0,"\"str\"":"Rows matched: 1 Changed: 0 Warnings: 0"}
+
View
102 t/ret.t
@@ -72,105 +72,3 @@ Content-Type: application/json
--- response_body chop
{"errcode":400,"errstr":"Invalid \"limit\" argument."}
-
-
-=== TEST 5: location internal rewrite
---- config
- location @err403 {
- rds_json_success_property ret;
- rds_json_ret 403 "Forbidden";
- }
-
- location /foo {
- error_page 403 = @err403;
- return 403;
- }
---- request
- GET /foo
---- response_headers
-Content-Type: application/json
---- response_body chop
-{"errcode":403,"errstr":"Forbidden","ret":false}
-
-
-
-=== TEST 6: rds_json_errcode_key
---- config
- location /foo {
- rds_json_errcode_key "ecode";
- rds_json_success_property ret;
- rds_json_ret 403 "Forbidden";
- }
---- request
- GET /foo
---- response_headers
-Content-Type: application/json
---- response_body chop
-{"ecode":403,"errstr":"Forbidden","ret":false}
-
-
-=== TEST 7: rds_json_errcode_key
---- config
- rds_json_errcode_key "ecoderoot";
-
- location /foo {
- rds_json_success_property ret;
- rds_json_ret 403 "Forbidden";
- }
---- request
- GET /foo
---- response_headers
-Content-Type: application/json
---- response_body chop
-{"ecoderoot":403,"errstr":"Forbidden","ret":false}
-
-
-=== TEST 8: rds_json_errcode_key
---- config
- rds_json_errcode_key "ecoderoot";
-
- location /foo {
- rds_json_errcode_key "ecode";
- rds_json_success_property ret;
- rds_json_ret 403 "Forbidden";
- }
---- request
- GET /foo
---- response_headers
-Content-Type: application/json
---- response_body chop
-{"ecode":403,"errstr":"Forbidden","ret":false}
-
-
-
-=== TEST 9: rds_json_errstr_key
---- config
- rds_json_errstr_key "msg";
-
- location /foo {
- rds_json_success_property ret;
- rds_json_ret 403 "Forbidden";
- }
---- request
- GET /foo
---- response_headers
-Content-Type: application/json
---- response_body chop
-{"errcode":403,"msg":"Forbidden","ret":false}
-
-
-=== TEST 10: rds_json_errstr_key
---- config
- rds_json_errstr_key "msg";
-
- location /foo {
- rds_json_errstr_key "msg2";
- rds_json_success_property ret;
- rds_json_ret 403 "Forbidden";
- }
---- request
- GET /foo
---- response_headers
-Content-Type: application/json
---- response_body chop
-{"errcode":403,"msg2":"Forbidden","ret":false}

0 comments on commit 25a5efc

Please sign in to comment.