Skip to content

Commit

Permalink
feat: support built-in variables in response_headers in mocking plugin (
Browse files Browse the repository at this point in the history
  • Loading branch information
MonkeyDLufy authored Jan 31, 2024
1 parent 9ed823e commit 43a567c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions apisix/plugins/mocking.lua
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ function _M.access(conf, ctx)

if conf.response_headers then
for key, value in pairs(conf.response_headers) do
value = core.utils.resolve_var(value, ctx.var)
core.response.add_header(key, value)
end
end
Expand Down
39 changes: 39 additions & 0 deletions t/plugin/mocking.t
Original file line number Diff line number Diff line change
Expand Up @@ -465,3 +465,42 @@ GET /hello
--- response_headers
X-Apisix: is, cool
X-Really: yes
=== TEST 21: set route (return headers support built-in variables)
--- 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,
[[{
"plugins": {
"mocking": {
"response_example": "hello world",
"response_headers": {
"X-Route-Id": "$route_id"
}
}
},
"uri": "/hello"
}]]
)
if code >= 300 then
ngx.status = code
end
ngx.say(body)
}
}
--- response_body
passed
=== TEST 22: hit route
--- request
GET /hello
--- response_headers
X-Route-Id: 1

0 comments on commit 43a567c

Please sign in to comment.