feat(proxy-rewrite): support multiple same-name headers in headers.add/set#13597
Draft
AlinsRan wants to merge 2 commits into
Draft
feat(proxy-rewrite): support multiple same-name headers in headers.add/set#13597AlinsRan wants to merge 2 commits into
AlinsRan wants to merge 2 commits into
Conversation
Allow headers.set and headers.add values to be an array (e.g. "foo": ["v1", "v2"]), producing multiple headers with the same name: - set replaces any incoming header with the listed values; - add appends the listed values to the existing ones. The map-based headers schema previously could not express same-name multi-value headers (a JSON object can't hold two values for one key); the array form closes that gap. remove is unchanged (it already takes an array of names). Backward compatible: string/number values keep working. Closes apache#13163
The echo helper joined same-name headers with ", ", so the assertions
("x-multi: val1, val2") could not tell a genuine multi-header result apart
from a single comma-joined value. Emit one line per header occurrence and
assert the repeated "x-multi: ..." lines, so the test actually proves that
set/add with an array produces multiple headers with the same name.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Allow
headers.setandheaders.addvalues inproxy-rewriteto be an array, producing multiple headers with the same name:setwith an array replaces any incoming header with the listed values.addwith an array appends the listed values to the existing ones.removeis unchanged (it already takes an array of names).Why
proxy-rewritemodelsheaders.add/setas a JSON object (map), which structurally cannot express same-name multi-value headers — a JSON object can't hold two values for one key. This is a real gap vs. other gateways that model header transforms as an ordered list of (name, value) pairs (Kongrequest-transformerappend.headers, Envoyrequest_headers_to_add, HAProxyadd-header). The array form closes it. Genuine use cases: gRPC metadata (repeated keys → repeated HTTP/2 headers) and backends/auth proxies that read repeated custom headers.Fully backward compatible: existing string/number values keep working; the array is an additive schema option. Each element still supports NGINX variables and
regex_uricaptures.This also gives the clean answer to the
remove + addordering confusion in #11587 — multi-value is a data-model feature, not an operation-order one.Which issue(s) this PR fixes
Closes #13163
Changes
apisix/plugins/proxy-rewrite.lua: schema allowsarray<string|number>foradd/setvalues; apply loop resolves each element (set→ oneset_headerwith a table;add→ oneadd_headerper element).t/plugin/proxy-rewrite.t: tests forset(replace with multiple) andadd(append multiple);t/lib/server.lua: echo helper joining same-name headers.docs/{en,zh}/.../proxy-rewrite.md: attribute docs + example.Checklist