MCPcopy
hub / github.com/mudler/LocalAI / parseForwarded

Function parseForwarded

core/http/middleware/baseurl.go:102–124  ·  view source on GitHub ↗

parseForwarded extracts the proto and host directives from the first element of an RFC 7239 Forwarded header (e.g. `for=x;proto=https;host=h, for=y`). Values may be quoted. Returns empty strings when absent or malformed so the caller can fall through to other signals.

(header string)

Source from the content-addressed store, hash-verified

100// Values may be quoted. Returns empty strings when absent or malformed so the
101// caller can fall through to other signals.
102func parseForwarded(header string) (proto, host string) {
103 if header == "" {
104 return "", ""
105 }
106 // Only the first element (closest proxy to the client) matters here.
107 if i := strings.IndexByte(header, ','); i >= 0 {
108 header = header[:i]
109 }
110 for _, directive := range strings.Split(header, ";") {
111 key, value, ok := strings.Cut(strings.TrimSpace(directive), "=")
112 if !ok {
113 continue
114 }
115 value = strings.Trim(strings.TrimSpace(value), `"`)
116 switch strings.ToLower(strings.TrimSpace(key)) {
117 case "proto":
118 proto = value
119 case "host":
120 host = value
121 }
122 }
123 return proto, host
124}

Callers 2

BaseURLFunction · 0.85
baseurl_test.goFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected