This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
2021-04-23 12:07:44 +00:00
|
|
|
package proxy
|
|
|
|
|
2021-05-11 18:02:36 +00:00
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
"net/http"
|
2021-06-19 13:24:51 +00:00
|
|
|
"strconv"
|
2021-05-11 18:02:36 +00:00
|
|
|
)
|
2021-04-23 12:07:44 +00:00
|
|
|
|
|
|
|
var xForwardedHost = http.CanonicalHeaderKey("X-Forwarded-Host")
|
|
|
|
|
|
|
|
func getHost(req *http.Request) string {
|
2021-05-11 18:02:36 +00:00
|
|
|
host := req.Host
|
2021-04-23 12:07:44 +00:00
|
|
|
if req.Header.Get(xForwardedHost) != "" {
|
2021-05-11 18:02:36 +00:00
|
|
|
host = req.Header.Get(xForwardedHost)
|
2021-04-23 12:07:44 +00:00
|
|
|
}
|
2021-05-11 18:02:36 +00:00
|
|
|
hostOnly, _, err := net.SplitHostPort(host)
|
|
|
|
if err != nil {
|
|
|
|
return host
|
|
|
|
}
|
|
|
|
return hostOnly
|
2021-04-23 12:07:44 +00:00
|
|
|
}
|
2021-06-19 13:24:51 +00:00
|
|
|
|
|
|
|
// toString Generic to string function, currently supports actual strings and integers
|
|
|
|
func toString(in interface{}) string {
|
|
|
|
switch v := in.(type) {
|
|
|
|
case string:
|
|
|
|
return v
|
|
|
|
case *string:
|
|
|
|
return *v
|
|
|
|
case int:
|
|
|
|
return strconv.Itoa(v)
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|