MCPcopy Create free account
hub / github.com/ContentSquare/chproxy / parseForwardedHeader

Function parseForwardedHeader

proxy_handler.go:85–109  ·  view source on GitHub ↗
(fwd string)

Source from the content-addressed store, hash-verified

83}
84
85func parseForwardedHeader(fwd string) string {
86 splits := strings.Split(fwd, ";")
87 if len(splits) == 0 {
88 return ""
89 }
90
91 for _, split := range splits {
92 trimmed := strings.TrimSpace(split)
93 if strings.HasPrefix(strings.ToLower(trimmed), "for=") {
94 forSplits := strings.Split(trimmed, ",")
95 if len(forSplits) == 0 {
96 return ""
97 }
98
99 addr := forSplits[0][4:]
100 trimmedAddr := strings.
101 NewReplacer("\"", "", "[", "", "]", "").
102 Replace(addr) // If IpV6, remove brackets and quotes.
103
104 return trimmedAddr
105 }
106 }
107
108 return ""
109}

Callers 1

parseDefaultProxyHeadersFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected