Skip to content

rhai: add new values() fn for headers with multiple values#2258

Merged
garypen merged 4 commits intodevfrom
garypen/2255-more-rhai-headers
Dec 13, 2022
Merged

rhai: add new values() fn for headers with multiple values#2258
garypen merged 4 commits intodevfrom
garypen/2255-more-rhai-headers

Conversation

@garypen
Copy link
Contributor

@garypen garypen commented Dec 13, 2022

fixes: #2255

We can't update the indexer until we release router 2.0, since that
would be an incompatible change, but we can add a new function which
provides access to multiple values.

Here's an illustrative snippet:

// Create some headers to work with:
response.headers["scalar"] = "value 1";
response.headers["array"] = ["value 1", "value 2", "value 3"];

// We still see scalar header keys as a single string
print(`scalar: ${response.headers["scalar"]}`);

// If we know we have an array use the `values` fn
print(`array: ${response.headers.values("array")}`);
print(`array[2]: ${response.headers.values("array")[2]}`);

// If we access a multi-value header using the indexer, then:
print(`array: ${response.headers["array"]}`);
// we get the existing behaviour, the first value as a string

Needs documentation DONE

Gary Pennington added 2 commits December 13, 2022 11:13
fixes: #2255

We can't update the indexer until we release router 2.0, since that
would be an incompatible change, but we can add a new function which
provides access to multiple values.

Here's an illustrative snippet:

// Create some headers to work with:
response.headers["scalar"] = "value 1";
response.headers["array"] = ["value 1", "value 2", "value 3"];

// We still see scalar header keys as a single string
print(`scalar: ${response.headers["scalar"]}`);

// If we know we have an array use the `values` fn
print(`array: ${response.headers.values("array")}`);
print(`array[2]: ${response.headers.values("array")[2]}`);

// If we access a multi-value header using the indexer, then:
print(`array: ${response.headers["array"]}`);
// we get the existing behaviour, the first value as a string
@garypen garypen requested a review from a team December 13, 2022 11:21
@garypen garypen self-assigned this Dec 13, 2022
@garypen garypen requested review from SimonSapin and bnjjj and removed request for a team December 13, 2022 11:21
@github-actions

This comment has been minimized.

@garypen garypen enabled auto-merge (squash) December 13, 2022 12:13
@garypen garypen merged commit e380758 into dev Dec 13, 2022
@garypen garypen deleted the garypen/2255-more-rhai-headers branch December 13, 2022 12:21
@BrynCooke BrynCooke added this to the v1.6.0 milestone Dec 13, 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

Successfully merging this pull request may close these issues.

rhai header handling requires some cleanup

2 participants