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

script: support multiple header values #3013

Merged
merged 1 commit into from
Apr 9, 2024

Conversation

AlexanderYastrebov
Copy link
Member

Introduce add and values methods to set and get multiple header values.

Introduce `add` and `values` methods to set and get multiple header values.

Signed-off-by: Alexander Yastrebov <alexander.yastrebov@zalando.de>
@AlexanderYastrebov AlexanderYastrebov added the major moderate risk, for example new API, small filter changes that have no risk like refactoring or logs label Apr 8, 2024
if k:lower() == "authorization" then
table.insert(t, k)
table.insert(t, ": TRUNCATED\r\n")
else
table.insert(t, k)
table.insert(t, ": ")
table.insert(t, v)
table.insert(t, table.concat(header.values(k), " "))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what logHeader filter does.

@@ -677,6 +683,30 @@ func setRequestHeader(f filters.FilterContext) func(*lua.LState) int {
}
}

func addRequestHeader(f filters.FilterContext) func(*lua.LState) int {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be possible to generalize this and reuse for request and response headers but for simplicity I decided to introduce separate functions to follow the style of existing single value setters/getters and also because they return closures.

expectedRequestHeader: http.Header{
"Foo": []string{"Bar", "Baz"},
"Qux": []string{"Bar, Baz"},
"Absent-Length": []string{"0"},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we test Foo-Length (I expect it to be 2) and Qux-Length (I expect it to be 1) here as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this case to show that length of empty values is zero

@szuecs
Copy link
Member

szuecs commented Apr 8, 2024

👍

1 similar comment
@RomanZavodskikh
Copy link
Contributor

👍

@AlexanderYastrebov AlexanderYastrebov merged commit 20d4dd7 into master Apr 9, 2024
14 checks passed
@AlexanderYastrebov AlexanderYastrebov deleted the script/support-multiple-header-values branch April 9, 2024 08:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
major moderate risk, for example new API, small filter changes that have no risk like refactoring or logs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants