0

I have a demand, is at server return response, send a request to other server, but openresty say API disabled in the context of body_filter_by_lua*. i use module resty.http. thanks

Mad-Hades
  • 25
  • 9

1 Answers1

0

You can change the main logic.

First issue subrequest to your upstream (location.capture or lua-resty-http)

Upon success you may first send the response downstream by Lua code and issue the next subrequest to your "other server" from Lua.

UPDATE - this doesn't work As second approach you may treat your "other server" as upstream and allow request to this upstream only if subrequest to original server will be successful.

For both scenarios you may use access_by_lua* and content_by_lua* where cosocket API is available.

Alexander Altshuler
  • 2,930
  • 1
  • 17
  • 27
  • in access_by_lua*, can't get response status, and in content_by_lua_*, i don't how to return html to user. 1: user -> server 2: server-> send current request -> other server 3: server -> send current response -> other server 4: return current response to user, not lua say or other. just server return – Mad-Hades Feb 14 '17 at 08:40
  • I don't understand your question. You may use ngx.say() to return html wiithin content_by_lua* – Alexander Altshuler Feb 14 '17 at 09:28
  • https://github.com/openresty/lua-nginx-module#ngxlocationcapture has good enough documentation about returned response, including status – Alexander Altshuler Feb 14 '17 at 09:29
  • i have see this document. i maybe return custom response, or return origin response. how to use ngx.say return origin response? – Mad-Hades Feb 14 '17 at 09:38
  • not just this. the first is get response status, and second is return origin response to user... but in content_by_lua need lua generate response.. i know how to get resposne status, but i don't know how to return origin response to user in content_by_lua_*. do u understand what i mean? friend... thx – Mad-Hades Feb 15 '17 at 02:06
  • Has been solved.in header_filter, i set content_len is nil, and body change body.. be work – Mad-Hades Feb 16 '17 at 07:33