Skip to content

Commit e526cae

Browse files
authored
feature: added the ngx_http_lua_ffi_balancer_recreate_request FFI function to allow recreation of request buffer in balancer phase. (openresty#1734)
1 parent c0e460a commit e526cae

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/ngx_http_lua_balancer.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,4 +753,43 @@ ngx_http_lua_ffi_balancer_get_last_failure(ngx_http_request_t *r,
753753
}
754754

755755

756+
int
757+
ngx_http_lua_ffi_balancer_recreate_request(ngx_http_request_t *r,
758+
char **err)
759+
{
760+
ngx_http_lua_ctx_t *ctx;
761+
ngx_http_upstream_t *u;
762+
763+
if (r == NULL) {
764+
*err = "no request found";
765+
return NGX_ERROR;
766+
}
767+
768+
u = r->upstream;
769+
770+
if (u == NULL) {
771+
*err = "no upstream found";
772+
return NGX_ERROR;
773+
}
774+
775+
ctx = ngx_http_get_module_ctx(r, ngx_http_lua_module);
776+
if (ctx == NULL) {
777+
*err = "no ctx found";
778+
return NGX_ERROR;
779+
}
780+
781+
if ((ctx->context & NGX_HTTP_LUA_CONTEXT_BALANCER) == 0) {
782+
*err = "API disabled in the current context";
783+
return NGX_ERROR;
784+
}
785+
786+
/* u->create_request can not be NULL since we are in balancer phase */
787+
ngx_http_lua_assert(u->create_request != NULL);
788+
789+
*err = NULL;
790+
791+
return u->create_request(r);
792+
}
793+
794+
756795
/* vi:set ft=c ts=4 sw=4 et fdm=marker: */

0 commit comments

Comments
 (0)