Skip to content

Commit 20d6558

Browse files
dndxagentzh
authored andcommitted
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) <agentzh@gmail.com>
1 parent df70821 commit 20d6558

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/ngx_http_lua_balancer.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,13 @@ ngx_http_lua_balancer_get_peer(ngx_peer_connection_t *pc, void *data)
314314

315315
if (ctx->exited && ctx->exit_code != NGX_OK) {
316316
rc = ctx->exit_code;
317-
if (rc == NGX_ERROR || rc == NGX_BUSY || rc == NGX_DECLINED) {
317+
if (rc == NGX_ERROR
318+
|| rc == NGX_BUSY
319+
|| rc == NGX_DECLINED
320+
#ifdef HAVE_BALANCER_STATUS_CODE_PATCH
321+
|| rc >= NGX_HTTP_SPECIAL_RESPONSE
322+
#endif
323+
) {
318324
return rc;
319325
}
320326

t/138-balancer.t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ qr{\[crit\] .*? connect\(\) to 0\.0\.0\.1:80 failed .*?, upstream: "http://0\.0\
5858
}
5959
--- request
6060
GET /t
61-
--- response_body_like: 500 Internal Server Error
62-
--- error_code: 500
61+
--- response_body_like: 403 Forbidden
62+
--- error_code: 403
6363
--- error_log
6464
[lua] balancer_by_lua:2: hello from balancer by lua! while connecting to upstream,
6565
--- no_error_log eval

0 commit comments

Comments
 (0)