mirror of
https://gitee.com/iresty/apisix.git
synced 2024-12-02 03:58:02 +08:00
fix(wasm): ensure the process body flag is independent (#6496)
This commit is contained in:
parent
66a5a2a44a
commit
380f762f30
@ -16,6 +16,7 @@
|
||||
--
|
||||
local core = require("apisix.core")
|
||||
local support_wasm, wasm = pcall(require, "resty.proxy-wasm")
|
||||
local ngx_var = ngx.var
|
||||
|
||||
|
||||
local schema = {
|
||||
@ -77,8 +78,12 @@ local function http_request_wrapper(self, conf, ctx)
|
||||
end
|
||||
|
||||
-- $wasm_process_req_body is predefined in ngx_tpl.lua
|
||||
local handle_body = ctx.var.wasm_process_req_body
|
||||
local handle_body = ngx_var.wasm_process_req_body
|
||||
if handle_body ~= '' then
|
||||
-- reset the flag so we can use it for the next Wasm plugin
|
||||
-- use ngx.var to bypass the cache
|
||||
ngx_var.wasm_process_req_body = ''
|
||||
|
||||
local body, err = core.request.get_body()
|
||||
if err ~= nil then
|
||||
core.log.error(name, ": failed to get request body: ", err)
|
||||
|
54
t/wasm/request-body.t
vendored
54
t/wasm/request-body.t
vendored
@ -42,6 +42,9 @@ wasm:
|
||||
- name: wasm-request-body
|
||||
priority: 7997
|
||||
file: t/wasm/request-body/main.go.wasm
|
||||
- name: wasm-request-body2
|
||||
priority: 7996
|
||||
file: t/wasm/request-body/main.go.wasm
|
||||
_EOC_
|
||||
$block->set_value("extra_yaml_config", $extra_yaml_config);
|
||||
});
|
||||
@ -150,3 +153,54 @@ hello
|
||||
--- grep_error_log eval
|
||||
qr/request get body: \w+/
|
||||
--- grep_error_log_out
|
||||
|
||||
|
||||
|
||||
=== TEST 6: ensure the process body flag is plugin independent
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local t = require("lib.test_admin").test
|
||||
local code, body = t('/apisix/admin/routes/1',
|
||||
ngx.HTTP_PUT,
|
||||
[[{
|
||||
"uri": "/hello",
|
||||
"upstream": {
|
||||
"type": "roundrobin",
|
||||
"nodes": {
|
||||
"127.0.0.1:1980": 1
|
||||
}
|
||||
},
|
||||
"plugins": {
|
||||
"wasm-request-body": {
|
||||
"conf": "{\"processReqBody\":true, \"start\":1, \"size\":3}"
|
||||
},
|
||||
"wasm-request-body2": {
|
||||
"conf": "{\"processReqBody\":false, \"start\":2, \"size\":3}"
|
||||
}
|
||||
}
|
||||
}]]
|
||||
)
|
||||
|
||||
if code >= 300 then
|
||||
ngx.status = code
|
||||
ngx.say(body)
|
||||
return
|
||||
end
|
||||
|
||||
ngx.say(body)
|
||||
}
|
||||
}
|
||||
--- response_body
|
||||
passed
|
||||
|
||||
|
||||
|
||||
=== TEST 7: hit
|
||||
--- request
|
||||
POST /hello
|
||||
hello
|
||||
--- grep_error_log eval
|
||||
qr/request get body: \w+/
|
||||
--- grep_error_log_out
|
||||
request get body: ell
|
||||
|
Loading…
Reference in New Issue
Block a user