EffectiveOrigin derives an origin URL from the request and host. Used for CORS headers and for dynamic per-host origin resolution.
(r *http.Request, host string)
| 151 | // EffectiveOrigin derives an origin URL from the request and host. |
| 152 | // Used for CORS headers and for dynamic per-host origin resolution. |
| 153 | func EffectiveOrigin(r *http.Request, host string) string { |
| 154 | if host == "" { |
| 155 | return "" |
| 156 | } |
| 157 | scheme := "https" |
| 158 | if proto := r.Header.Get("X-Forwarded-Proto"); proto != "" { |
| 159 | scheme = strings.ToLower(proto) |
| 160 | } else if r.TLS == nil { |
| 161 | scheme = "http" |
| 162 | } |
| 163 | return scheme + "://" + host |
| 164 | } |
| 165 | |
| 166 | // buildAllowedHosts extracts host[:port] from each origin URL. |
| 167 | // E.g. "http://patchmon-local:3000" -> "patchmon-local:3000". |