spacewander commented on code in PR #6968:
URL: https://github.com/apache/apisix/pull/6968#discussion_r867480639


##########
apisix/plugins/ext-plugin/init.lua:
##########
@@ -682,6 +682,107 @@ local rpc_handlers = {
 
         return true
     end,
+    nil, -- ignore RPC_EXTRA_INFO, already processed during RPC_HTTP_REQ_CALL 
interaction
+    function (conf, ctx, sock, entry)
+        local lrucache_id = core.lrucache.plugin_ctx_id(ctx, entry)
+        local token, err = core.lrucache.plugin_ctx(lrucache, ctx, entry, 
rpc_call,
+                                                    
constants.RPC_PREPARE_CONF, conf, ctx,
+                                                    lrucache_id)
+        if not token then
+            return nil, err
+        end
+
+        builder:Clear()
+        local var = ctx.var
+
+        local res = ctx.runner_ext_response
+        local textEntries = {}
+        local hdrs = res.headers
+        for key, val in pairs(hdrs) do
+            local ty = type(val)
+            if ty == "table" then
+                for _, v in ipairs(val) do
+                    core.table.insert(textEntries, build_headers(var, builder, 
key, v))
+                end
+            else
+                core.table.insert(textEntries, build_headers(var, builder, 
key, val))
+            end
+        end
+        local len = #textEntries
+        http_resp_call_req.StartHeadersVector(builder, len)
+        for i = len, 1, -1 do
+            builder:PrependUOffsetTRelative(textEntries[i])
+        end
+        local hdrs_vec = builder:EndVector(len)
+
+        local id = generate_id()
+        local status = res.status
+
+        http_resp_call_req.Start(builder)
+        http_resp_call_req.AddId(builder, id)
+        http_resp_call_req.AddStatus(builder, status)
+        http_resp_call_req.AddConfToken(builder, token)
+        http_resp_call_req.AddHeaders(builder, hdrs_vec)
+
+        local req = http_resp_call_req.End(builder)
+        builder:Finish(req)
+
+        local ok, err = send(sock, constants.RPC_HTTP_RESP_CALL, 
builder:Output())
+        if not ok then
+            return nil, "failed to send RPC_HTTP_RESP_CALL: " .. err
+        end
+
+        local ty, resp = receive(sock)
+        if ty == nil then
+            return nil, "failed to receive RPC_HTTP_RESP_CALL: " .. resp
+        end
+
+        if ty ~= constants.RPC_HTTP_RESP_CALL then
+            return nil, "failed to receive RPC_HTTP_RESP_CALL: unexpected type 
" .. ty
+        end
+
+        local buf = flatbuffers.binaryArray.New(resp)
+        local call_resp = http_resp_call_resp.GetRootAsResp(buf, 0)
+        local len = call_resp:HeadersLength()
+        if len > 0 then
+            local resp_headers = {}
+            for i = 1, len do
+                local entry = call_resp:Headers(i)
+                local name = str_lower(entry:Name())
+                if not exclude_resp_header[name] then
+                    if resp_headers[name] == nil then
+                        core.response.set_header(name, entry:Value())
+                        resp_headers[name] = true
+                    else
+                        core.response.add_header(name, entry:Value())
+                    end
+                end
+            end
+        else
+            -- Filter out origin headeres
+            for k, v in pairs(res.headers) do
+                if not exclude_resp_header[str_lower(k)] then
+                    core.response.set_header(k, v)
+                end
+            end
+        end
+
+        local body
+        local len = call_resp:BodyLength()
+        if len > 0 then
+            -- TODO: support empty body
+            body = call_resp:BodyAsString()
+        end
+        local code = call_resp:Status()
+        core.log.info("recv resp, code: ", code, " body: ", body, " len: ", 
len)
+
+        if code == 0 then
+            -- runner change body only, we should set code.
+            code = body and res.status or nil

Review Comment:
   Ping @soulbird 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to