From 99216ffe59add255796613eef8db34a517d95f7c Mon Sep 17 00:00:00 2001 From: yusing Date: Tue, 24 Sep 2024 18:30:25 +0800 Subject: [PATCH] fixed subdomain matching for sub-sub-subdomain and so on, now return 404 when subdomain is missing --- src/route/http_route.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/route/http_route.go b/src/route/http_route.go index d8f817da..b8533764 100755 --- a/src/route/http_route.go +++ b/src/route/http_route.go @@ -148,7 +148,12 @@ func ProxyHandler(w http.ResponseWriter, r *http.Request) { } func findMux(host string) (*http.ServeMux, E.NestedError) { - sd := strings.Split(host, ".")[0] + hostSplit := strings.Split(host, ".") + n := len(hostSplit) + if n <= 2 { + return nil, E.Missing("subdomain") + } + sd := strings.Join(hostSplit[:n-2], ".") if r, ok := httpRoutes.Load(PT.Alias(sd)); ok { return r.mux, nil }