mirror of
https://github.com/bingohuang/docker-labs.git
synced 2025-10-04 17:33:21 +08:00
Allow to send subdomains but forward header as is to backends
This commit is contained in:
@@ -13,10 +13,9 @@ import (
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
func getTargetInfo(vars map[string]string, req *http.Request) (string, string, string) {
|
||||
func getTargetInfo(vars map[string]string, req *http.Request) (string, string) {
|
||||
node := vars["node"]
|
||||
port := vars["port"]
|
||||
host := vars["host"]
|
||||
hostPort := strings.Split(req.Host, ":")
|
||||
|
||||
// give priority to the URL host port
|
||||
@@ -37,14 +36,7 @@ func getTargetInfo(vars map[string]string, req *http.Request) (string, string, s
|
||||
}
|
||||
}
|
||||
|
||||
if len(host) > 0 {
|
||||
// Remove last "." from host
|
||||
host = strings.TrimSuffix(host, ".")
|
||||
} else {
|
||||
host = req.Host
|
||||
}
|
||||
|
||||
return node, port, host
|
||||
return node, port
|
||||
|
||||
}
|
||||
|
||||
@@ -64,7 +56,7 @@ func NewMultipleHostReverseProxy() *httputil.ReverseProxy {
|
||||
}
|
||||
director := func(req *http.Request) {
|
||||
v := mux.Vars(req)
|
||||
node, port, host := getTargetInfo(v, req)
|
||||
node, port := getTargetInfo(v, req)
|
||||
|
||||
if port == "443" {
|
||||
// Only proxy http for now
|
||||
@@ -74,7 +66,6 @@ func NewMultipleHostReverseProxy() *httputil.ReverseProxy {
|
||||
req.URL.Scheme = "http"
|
||||
}
|
||||
|
||||
req.Host = host
|
||||
req.URL.Host = fmt.Sprintf("%s:%s", node, port)
|
||||
}
|
||||
|
||||
|
@@ -16,7 +16,7 @@ func NewMultipleHostWebsocketReverseProxy() *wsutil.ReverseProxy {
|
||||
director := func(req *http.Request) {
|
||||
v := mux.Vars(req)
|
||||
|
||||
node, port, host := getTargetInfo(v, req)
|
||||
node, port := getTargetInfo(v, req)
|
||||
|
||||
if port == "443" {
|
||||
// Only proxy http for now
|
||||
@@ -25,7 +25,6 @@ func NewMultipleHostWebsocketReverseProxy() *wsutil.ReverseProxy {
|
||||
// Only proxy http for now
|
||||
req.URL.Scheme = "ws"
|
||||
}
|
||||
req.Host = host
|
||||
req.URL.Host = fmt.Sprintf("%s:%s", node, port)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user