github.com/anycable/anycable-go@v1.5.1/server/headers_extractor.go (about) 1 package server 2 3 import ( 4 "net" 5 "net/http" 6 "strings" 7 ) 8 9 type HeadersExtractor interface { 10 FromRequest(r *http.Request) map[string]string 11 } 12 13 type DefaultHeadersExtractor struct { 14 Headers []string 15 Cookies []string 16 } 17 18 func (h *DefaultHeadersExtractor) FromRequest(r *http.Request) map[string]string { 19 res := make(map[string]string) 20 21 for _, header := range h.Headers { 22 value := r.Header.Get(header) 23 if strings.ToLower(header) == "cookie" { 24 value = parseCookies(value, h.Cookies) 25 } 26 27 if value != "" { 28 res[header] = value 29 } 30 } 31 res[remoteAddrHeader], _, _ = net.SplitHostPort(r.RemoteAddr) 32 33 return res 34 }