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

Add GetAllHeaders method to golang HTTP filter #33821

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

willemveerman
Copy link

@willemveerman willemveerman commented Apr 26, 2024

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:]

Copy link

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.

🐱

Caused by: #33821 was opened by willemveerman.

see: more, trace.

Copy link

As a reminder, PRs marked as draft will not be automatically assigned reviewers,
or be handled by maintainer-oncall triage.

Please mark your PR as ready when you want it to be reviewed!

🐱

Caused by: #33821 was opened by willemveerman.

see: more, trace.

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>
Signed-off-by: Willem Veerman <6502426+willemveerman@users.noreply.github.com>
@willemveerman willemveerman changed the title initial WIP GetAllHeaders Add GetAllHeaders method to golang HTTP filter Apr 29, 2024
Signed-off-by: Willem Veerman <6502426+willemveerman@users.noreply.github.com>
@willemveerman willemveerman marked this pull request as ready for review May 6, 2024 14:45
Copy link
Member

@doujiang24 doujiang24 left a 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.

contrib/golang/filters/http/source/go/pkg/http/type.go Outdated Show resolved Hide resolved
@phlax phlax self-assigned this May 7, 2024
Signed-off-by: Willem Veerman <6502426+willemveerman@users.noreply.github.com>
@phlax
Copy link
Member

phlax commented May 10, 2024

@doujiang24 i think this may be waiting for further review

@willemveerman
Copy link
Author

@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
Copy link
Member

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.

Copy link
Author

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?

Copy link
Member

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?

Copy link
Author

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)
	}

Copy link
Author

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

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.

None yet

3 participants