Hello,
I'm looking for a way to dynamically select an upstream based on the client body request. For example, if the request body is contain text "
getProfile" then it will go to /
getProfile location, another request go to /proxy location.
location / {
content_by_lua_block {
server = require "resty.websocket.server"
wb, err = server:new()
local data, typ, err = wb:recv_frame()
local cjson = require('cjson')
local datajson = cjson.decode(data)
if datajson["action"]=="getProfile" then
return ngx.exec("@getProfile")
else
return ngx.exec("@proxy")
end
}
}
location /
getProfile {
content_by_lua_block {
response="
getProfile response"
local bytes, err = wb:send_text(response)
}
}
location /proxy {
content_by_lua_block {
local proxy = require "resty.websocket.proxy"
local wp, err = proxy.new()
local done, err = wp:execute()
}
}
When I make a test request, I got a error: "*2 lua entry thread aborted: runtime error: attempt to call ngx.exec after sending out response headers"
So I think my logic is totally wrong. Do you have any idea?
Thank you,
Tan