Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: Invalid filter with response-rewrite in apache/apisix:2.99.0-debian #8087

Closed
ada012 opened this issue Oct 14, 2022 · 3 comments
Closed

Comments

@ada012
Copy link

ada012 commented Oct 14, 2022

Current Behavior

Hi, I would also like to use nginx sub_filter in apisix, but it still doesn't work when I use it in apache/apisix:2.99.0-debian,and I see an identical issue and have been merged,there #5451

Expected Behavior

Before content:

<head>
    <title>test</title>
    <meta charset="utf-8">
</head>

ideally, use the content after filter:

<head>
    <title>test</title>
    <meta charset="utf-8">
    <script>console.log(1)</script>
</head>

However, it does not take effect

Error Logs

No response

Steps to Reproduce

  1. Use docker-compose deployment
  2. In the plugin/market path, enable the response-rewrite plugin
  3. configuration parameters are as follows
{
  "disable": false,
  "filters": [
    {
      "regex": "</head>",
      "replace": "<script>console.log(1)</script></head>",
      "scope": "global"
    }
  ],
  "headers": {
    "set": {
      "x-powered-by": "",
      "x-server-balancer_addr": "$balancer_ip:$balancer_port"
    }
  },
  "vars": [
    [
      "status",
      "==",
      200
    ],
    [
      "content-type",
      "==",
      "text/html; charset=utf-8"
    ]
  ]
}

Environment

  • APISIX version (run apisix version): apache/apisix:2.99.0-debian
  • APISIX Dashboard version, if relevant: apache/apisix-dashboard:2.13-alpine
@ada012 ada012 changed the title bug: bug: Invalid filter with response-rewrite in apache/apisix:2.99.0-debian Oct 14, 2022
@mscb402
Copy link
Contributor

mscb402 commented Oct 18, 2022

Please read document https://apisix.apache.org/docs/apisix/terminology/plugin/#plugin-common-configuration
Currently apisix only support request parameters, so your configuration is not right. You should remove condition on vars

"vars": [
    [
      "status",
      "==",
      200
    ],
    [
      "content-type",
      "==",
      "text/html; charset=utf-8"
    ]
  ]

to

"var": []

@soulbird
Copy link
Contributor

<head>
    <title>test</title>
    <meta charset="utf-8">
</head>

Can you give a full upstream response? Contains response headers and a response body.

@soulbird
Copy link
Contributor

Please read document https://apisix.apache.org/docs/apisix/terminology/plugin/#plugin-common-configuration Currently apisix only support request parameters, so your configuration is not right. You should remove condition on vars

"vars": [
    [
      "status",
      "==",
      200
    ],
    [
      "content-type",
      "==",
      "text/html; charset=utf-8"
    ]
  ]

to

"var": []

The response-rewrite plugin has already received the response when executing the vars expression, so it can contain some variables in the response, you can check this test case: https://github.com/apache/apisix/blob/master/ t/plugin/response-rewrite2.t#L236

@ada012 ada012 closed this as completed Nov 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants