Skip to content

Commit

Permalink
feature: balancer_by_lua*: now the user Lua code can terminate the cu…
Browse files Browse the repository at this point in the history
…rrent request with arbitrary HTTP response status codes via ngx.exit().

Signed-off-by: Yichun Zhang (agentzh) <agentzh@gmail.com>
  • Loading branch information
dndx authored and agentzh committed Jun 28, 2017
1 parent df70821 commit 20d6558
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/ngx_http_lua_balancer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions t/138-balancer.t
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 20d6558

Please sign in to comment.