Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixed a bug in rds_json_ret when errstr is empty.

  • Loading branch information...
commit a5440a96e2ab24f7e25b3c661082ff0c0ea076ab 1 parent b2cb680
Yichun Zhang agentzh authored
6 src/ngx_http_rds_json_filter_module.c
View
@@ -4,7 +4,7 @@
*/
-#define DDEBUG 0
+#define DDEBUG 1
#include "ddebug.h"
#include "ngx_http_rds_json_filter_module.h"
@@ -316,7 +316,7 @@ ngx_http_rds_json_ret(ngx_conf_t *cf, ngx_command_t *cmd,
if (value[2].len == 0) {
ngx_memzero(jlcf->errstr, sizeof(ngx_http_complex_value_t));
- return NGX_OK;
+ goto done;
}
ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
@@ -329,6 +329,8 @@ ngx_http_rds_json_ret(ngx_conf_t *cf, ngx_command_t *cmd,
return NGX_CONF_ERROR;
}
+done:
+
clcf = ngx_http_conf_get_module_loc_conf(cf,
ngx_http_core_module);
if (clcf == NULL) {
14 test/t/openresty.t
View
@@ -27,12 +27,11 @@ our $config = <<'_EOC_';
xss_callback_arg _callback;
location = '/=/view/PostsByMonth/~/~' {
-
if ($arg_year !~ '^\d{4}$') {
- echo_duplicate 1 '{"errcode":400,"errstr":"Bad year argument"}';
+ rds_json_ret 400 'Bad "year" argument';
}
if ($arg_month !~ '^\d{1,2}$') {
- echo_duplicate 1 '{"errcode":400,"errstr":"Bad month argument"}';
+ rds_json_ret 400 'Bad "month" argument';
}
drizzle_query
@@ -52,13 +51,8 @@ order by created asc";
rds_json on;
}
- location @err500 {
- echo_duplicate 1 '{"errcode":500,"errstr":"Internal Server Error"}';
- }
-
- location @err502 {
- echo_duplicate 1 '{"errcode":502,"errstr":"Bad Gateway"}';
- }
+ location @err500 { rds_json_ret 500 "Internal Server Error"; }
+ location @err502 { rds_json_ret 502 "Bad Gateway"; }
location @err503 {
echo_duplicate 1 '{"errcode":503,"errstr":"Service Unavailable"}';
18 test/t/ret.t
View
@@ -27,7 +27,21 @@ Content-Type: application/json
-=== TEST 2: set content type
+=== TEST 2: empty errstr
+--- config
+ location /foo {
+ rds_json_ret 400 "";
+ }
+--- request
+ GET /foo
+--- response_headers
+Content-Type: application/json
+--- response_body chop
+{"errcode":400}
+
+
+
+=== TEST 3: set content type
--- config
rds_json_content_type 'text/javascript';
location /foo {
@@ -42,7 +56,7 @@ Content-Type: text/javascript
-=== TEST 3: JSON escaping
+=== TEST 4: JSON escaping
--- config
location /foo {
if ($arg_limit !~ '^\d+$') {
Please sign in to comment.
Something went wrong with that request. Please try again.