From 20d6558b074f1bda3584827412f2e364aeb00b0f Mon Sep 17 00:00:00 2001 From: Datong Sun Date: Fri, 23 Jun 2017 19:07:06 -0700 Subject: [PATCH] feature: balancer_by_lua*: now the user Lua code can terminate the current request with arbitrary HTTP response status codes via ngx.exit(). Signed-off-by: Yichun Zhang (agentzh) --- src/ngx_http_lua_balancer.c | 8 +++++++- t/138-balancer.t | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/ngx_http_lua_balancer.c b/src/ngx_http_lua_balancer.c index 03d9eac082..2fa634eb4d 100644 --- a/src/ngx_http_lua_balancer.c +++ b/src/ngx_http_lua_balancer.c @@ -314,7 +314,13 @@ ngx_http_lua_balancer_get_peer(ngx_peer_connection_t *pc, void *data) if (ctx->exited && ctx->exit_code != NGX_OK) { rc = ctx->exit_code; - if (rc == NGX_ERROR || rc == NGX_BUSY || rc == NGX_DECLINED) { + if (rc == NGX_ERROR + || rc == NGX_BUSY + || rc == NGX_DECLINED +#ifdef HAVE_BALANCER_STATUS_CODE_PATCH + || rc >= NGX_HTTP_SPECIAL_RESPONSE +#endif + ) { return rc; } diff --git a/t/138-balancer.t b/t/138-balancer.t index fc2617350a..ddd0da577a 100644 --- a/t/138-balancer.t +++ b/t/138-balancer.t @@ -58,8 +58,8 @@ qr{\[crit\] .*? connect\(\) to 0\.0\.0\.1:80 failed .*?, upstream: "http://0\.0\ } --- request GET /t ---- response_body_like: 500 Internal Server Error ---- error_code: 500 +--- response_body_like: 403 Forbidden +--- error_code: 403 --- error_log [lua] balancer_by_lua:2: hello from balancer by lua! while connecting to upstream, --- no_error_log eval