Skip to content

bug: proxy-rewrite and proxy-mirror do not work together #8167

Description

@bzp2010

Current Behavior

The route configuration (omitted some irrelevant content):

{
    "uri": "/v1/hello/*",
    "plugins": {
        "proxy-mirror": {
            "sample_ratio": 1,
            "host": "http://mirror.api:8082"
        },
        "proxy-rewrite": {
            "regex_uri": [
                "/v1/(.*)",
                "/$1"
            ],
            "_meta": {
                "priority": 2000
            }
        }
    }
}

The client uses this URI to request:

GET /v1/hello

Requests to the upstream will be rewritten as:

GET /hello

But the request to the mirror address is still:

GET /v1/hello

So the URI rewritten in proxy-rewrite does not actually take effect for proxy-mirror. (I have overridden the proxy-rewrite priority via _meta.priority and it will be executed first)

Expected Behavior

The modified URI in proxy-rewrite will take effect for proxy-mirror.

Error Logs

No response

Steps to Reproduce

  1. Create a route by referring to the route configuration in the current behavior.
  2. Request API
  3. Check mirror service log

Explanation of reasons:
proxy-rewrite gets the URI from ctx.var.uri, writes it to the upstream_uri variable, and subsequently uses that variable instead of the original uri when forwarding upstream. proxy-mirror does not take this into account and uses the original uri variable directly. I think it should behave in such a way that the uri is used first and the upstream_uri is used when the value does not match the upstream_uri. If necessary we also need to modify the proxy-rewrite priority so that it takes precedence over proxy-mirror.

Environment

  • APISIX version (run apisix version): 2.15.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions