openresty on body_filter_by_lua 发送套接字

openresty on body_filter_by_lua send socket

我有一个需求,是在服务器return响应,向其他服务器发送请求,但是openresty说API在body_filter_by_lua*的上下文中被禁用。我使用模块 resty.http。 谢谢

你可以改变主逻辑。

首先向您的上游发出子请求(location.capture 或 lua-resty-http)

成功后,您可以先通过 Lua 代码向下游发送响应,然后从 Lua 向您的 "other server" 发出下一个子请求。

更新 - 这不起作用 作为第二种方法,您可以将 "other server" 视为上游,并且仅当对原始服务器的子请求成功时才允许对该上游的请求。

对于这两种情况,您可以使用 access_by_lua* 和 content_by_lua*,其中 cosocket API 可用。