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
Add GetAllHeaders method to golang HTTP filter #33821
base: main
Are you sure you want to change the base?
Add GetAllHeaders method to golang HTTP filter #33821
Conversation
Hi @willemveerman, welcome and thank you for your contribution. We will try to review your Pull Request as quickly as possible. In the meantime, please take a look at the contribution guidelines if you have not done so already. |
Signed-off-by: Willem Veerman <6502426+willemveerman@users.noreply.github.com>
Signed-off-by: Willem Veerman <6502426+willemveerman@users.noreply.github.com>
Signed-off-by: Willem Veerman <6502426+willemveerman@users.noreply.github.com>
14154cb
to
90660b5
Compare
Signed-off-by: Willem Veerman <6502426+willemveerman@users.noreply.github.com>
Signed-off-by: Willem Veerman <6502426+willemveerman@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, we need some tests though the implementation is simple.
Signed-off-by: Willem Veerman <6502426+willemveerman@users.noreply.github.com>
@doujiang24 i think this may be waiting for further review |
I still need to add the tests |
h.initTrailers() | ||
copied_headers := make(map[string][]string) | ||
for key, values := range h.headers { | ||
copied_headers[key] = values |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this won't clone a slice too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't fully understand, can you elaborate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is shallow copy now, here is an example:
// slice
s := []int{1, 2, 3}
d := s
s[0] = 4
println(d[0]) // 4
I think we need deep clone for safety, thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see what you mean.... This should do what we need
for key, value := range h.headers {
copied_headers[key] = append(value[:0:0], value...)
}
Or we could do this
for key, value := range h.headers {
copied_headers[key] = make([]string, len(value))
copy(copied_headers[key], value)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The second option is more readable imo
Commit Message: Add GetAllHeaders method to golang HTTP filter
Additional Description: Adds a new method which returns a copy of the underlying
map[string][]string
object which contains all the request headers.Risk Level: Low
Testing: local manual testing
Docs Changes: none required (only changes the capabilities afforded to the plugin, does not change envoy itself)
Release Notes:
Platform Specific Features:
[Optional Runtime guard:]
[Optional Fixes #Issue]
[Optional Fixes commit #PR or SHA]
[Optional Deprecated:]
[Optional API Considerations:]