Skip to content

feat: support built-in variables in response_headers in mocking plugin #10868

Description

@MonkeyDLufy

Current Behavior

curl -i "http://127.0.0.1:9180/apisix/admin/routes" -X PUT -d ' { "id": "test-cors", "uri": "/cjx/*", "methods": ["OPTIONS"], "priority": 1, "vars": [["server_port","==","9080"]], "plugins": { "mocking": { "response_status": 200, "response_example": "cjx-test", "response_headers": { "Access-Control-Allow-Origin": "$route_id", "Vary": "Origin", "Access-Control-Allow-Methods": "GET,POST,DELETE,PUT,OPTIONS", "Access-Control-Allow-Headers": "$http_Access_Control_Request_Header", "Access-Control-Allow-Credentials": "true", "Access-Control-Max-Age": "18000" } } } }'

$route_id and $http_Access_Control_Request_Header can't work.

< HTTP/1.1 200 OK
< Date: Thu, 25 Jan 2024 09:14:48 GMT
< Content-Type: application/json;charset=utf8
< Transfer-Encoding: chunked
< Connection: keep-alive
< x-mock-by: APISIX/3.7.0
< Access-Control-Allow-Headers: $http_Access_Control_Request_Header
< Access-Control-Allow-Credentials: true
< Access-Control-Allow-Origin: $route_id
< Vary: Origin
< Access-Control-Allow-Methods: GET,POST,DELETE,PUT,OPTIONS
< Access-Control-Max-Age: 18000
< Server: APISIX/3.7.0
<

Expected Behavior

$http_Access_Control_Request_Header and $route_id can work as APISIX variable and NGINX variable

Error Logs

No response

Steps to Reproduce

curl -i "http://127.0.0.1:9180/apisix/admin/routes" -X PUT -d ' { "id": "test-cors", "uri": "/cjx/*", "methods": ["OPTIONS"], "priority": 1, "vars": [["server_port","==","9080"]], "plugins": { "mocking": { "response_status": 200, "response_example": "cjx-test", "response_headers": { "Access-Control-Allow-Origin": "$route_id", "Vary": "Origin", "Access-Control-Allow-Methods": "GET,POST,DELETE,PUT,OPTIONS", "Access-Control-Allow-Headers": "$http_Access_Control_Request_Header", "Access-Control-Allow-Credentials": "true", "Access-Control-Max-Age": "18000" } } } }'

Environment

  • APISIX version (run apisix version):
  • Operating system (run uname -a):
  • OpenResty / Nginx version (run openresty -V or nginx -V):
  • etcd version, if relevant (run curl http://127.0.0.1:9090/v1/server_info):
  • APISIX Dashboard version, if relevant:
  • Plugin runner version, for issues related to plugin runners:
  • LuaRocks version, for installation issues (run luarocks --version):

quickstartapisix

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status
    ✅ Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions