Skip to content

Commit 9e5cd78

Browse files
committed
connect: router fixes
1 parent d9599fe commit 9e5cd78

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

connect/main.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package main
22

33
import (
44
"context"
5-
// "fmt"
5+
"fmt"
66
"net"
77
"net/http"
88
"os"
@@ -92,17 +92,21 @@ Options:
9292
}
9393
})
9494

95+
service := strings.ToLower(server.RequireService())
96+
envService := strings.ToLower(fmt.Sprintf("%s-%s", server.RequireEnv(), server.RequireService()))
97+
9598
connectRouter := func(w http.ResponseWriter, r *http.Request) {
9699
host := r.Header.Get("X-Forwarded-Host")
97100
if host == "" {
98101
host = r.Header.Get("Host")
99102
}
100103

101-
sub := strings.SplitAfterN(host, ".", 2)[0]
102-
if sub == "connect" {
103-
// the host is connect.<domain>
104+
sub := strings.ToLower(strings.SplitN(host, ".", 2)[0])
105+
switch sub {
106+
case service, envService:
107+
// the host is connect.<domain> or <env>-connect.<domain>
104108
connectHandler.Connect(w, r)
105-
} else {
109+
default:
106110
// the host is <auth>.connect.<domain>
107111
proxyConnectHandler.Connect(w, r)
108112
}

connect/transport_proxy.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ func (self *ProxyConnectHandler) Connect(w http.ResponseWriter, r *http.Request)
185185
host = r.Header.Get("Host")
186186
}
187187

188-
hostProxyId := strings.SplitAfterN(host, ".", 2)[0]
188+
hostProxyId := strings.SplitN(host, ".", 2)[0]
189189
proxyId, err := model.ParseSignedProxyId(hostProxyId)
190190
if err != nil {
191191
proxyId, err = model.ParseEncodedProxyId(hostProxyId)
@@ -213,7 +213,7 @@ func (self *ProxyConnectHandler) Connect(w http.ResponseWriter, r *http.Request)
213213
http.Error(w, "Malformed auth", http.StatusInternalServerError)
214214
return
215215
}
216-
signedProxyId := strings.SplitAfterN(string(combinedSignedProxyId), ":", 2)[0]
216+
signedProxyId := strings.SplitN(string(combinedSignedProxyId), ":", 2)[0]
217217
headerProxyId, err := model.ParseSignedProxyId(signedProxyId)
218218
if err != nil || proxyId != headerProxyId {
219219
http.Error(w, "Not authorized", http.StatusUnauthorized)

0 commit comments

Comments
 (0)