improved tracing for debug

This commit is contained in:
yusing
2024-10-06 06:06:29 +08:00
parent 01ff63a007
commit aa6fafd52f
4 changed files with 149 additions and 30 deletions

View File

@@ -2,7 +2,6 @@ package http
import (
"net/http"
"slices"
)
func RemoveHop(h http.Header) {
@@ -25,18 +24,30 @@ func CopyHeader(dst, src http.Header) {
}
}
func FilterHeaders(h http.Header, allowed []string) {
if allowed == nil {
return
func FilterHeaders(h http.Header, allowed []string) http.Header {
if len(allowed) == 0 {
return h
}
for i := range allowed {
allowed[i] = http.CanonicalHeaderKey(allowed[i])
filtered := make(http.Header)
for i, header := range allowed {
values := h.Values(header)
if len(values) == 0 {
continue
}
filtered[http.CanonicalHeaderKey(allowed[i])] = append([]string(nil), values...)
}
for key := range h {
if !slices.Contains(allowed, key) {
h.Del(key)
return filtered
}
func HeaderToMap(h http.Header) map[string]string {
result := make(map[string]string)
for k, v := range h {
if len(v) > 0 {
result[k] = v[0] // Take the first value
}
}
return result
}