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

Merged
merged 16 commits into from May 16, 2024
3 changes: 3 additions & 0 deletions contrib/golang/common/go/api/type.go
Expand Up @@ -131,6 +131,9 @@ type HeaderMap interface {

// RangeWithCopy calls f sequentially for each key and value copied from the map.
RangeWithCopy(f func(key, value string) bool)

// GetAllHeaders returns all the headers.
GetAllHeaders() map[string][]string
}

type RequestHeaderMap interface {
Expand Down
16 changes: 16 additions & 0 deletions contrib/golang/filters/http/source/go/pkg/http/type.go
Expand Up @@ -155,6 +155,14 @@ func (h *requestOrResponseHeaderMapImpl) RangeWithCopy(f func(key, value string)
}
}

func (h *requestOrResponseHeaderMapImpl) GetAllHeaders() map[string][]string {
h.mutex.Lock()
defer h.mutex.Unlock()
h.initHeaders()
copied_headers := h.headers
willemveerman marked this conversation as resolved.
Show resolved Hide resolved
return copied_headers
}

// api.RequestHeaderMap
type requestHeaderMapImpl struct {
requestOrResponseHeaderMapImpl
Expand Down Expand Up @@ -318,6 +326,14 @@ func (h *requestOrResponseTrailerMapImpl) RangeWithCopy(f func(key, value string
}
}

func (h *requestOrResponseTrailerMapImpl) GetAllHeaders() map[string][]string {
h.mutex.Lock()
defer h.mutex.Unlock()
h.initTrailers()
copied_headers := h.headers
return copied_headers
}

// api.RequestTrailerMap
type requestTrailerMapImpl struct {
requestOrResponseTrailerMapImpl
Expand Down