Skip to content

bug: proxy-rewrite header priority wrong #11587

Open
@bpasson

Description

@bpasson

Current Behavior

The current priority for header operations is: add > remove > set. This makes it impossible to handle the use-case where you want to add multiple headers with the same name but first remove all the headers with that name. The following configuration would make sense in my opinion:

"proxy-rewrite": {
   "headers": {
       "remove: ["foo"]
       "add": {
              "foo": "bar1",
              "foo": "bar2",
        }
    }
}

But due to the header priority add > remove > set this leads to no foo headers, as first they are added and then all removed again.

Expected Behavior

The expected behaviour would be to have both foo headers added and all earlier foo headers removed. For this to work the priority order should be remove > set > add. The set operation is basically a shortcut for remove, add but is confusing when you need a header multiple times, which set does not allow.

Error Logs

No response

Steps to Reproduce

  1. Run APISIX via docker image
  2. Create a route:
{
  "uri": "/*",
  "name": "httpbin-demo",
  "host": "httpbin.org",
  "upstream": {
    "scheme": "https",
    "type": "roundrobin",
    "nodes": {
      "httpbin.org:443": 1
    }
  },
  "plugins": {
    "proxy-rewrite": {
      "headers": {
        "remove": ["foo"],
        "add": {
          "foo": "bar2",
          "foo": "bar3"
        }
      }
    }
  }
}
  1. Test using `curl -H"foo: bar1" -H"Host: httpbin.org" http://localhost:9080/anything

The resulting json is missing the expected foo: bar1 and foo: bar2 headers.

Environment

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    📋 Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions