|
@@ -155,6 +155,9 @@ func (h *ProxyHandler) handleRootRouting(w http.ResponseWriter, r *http.Request)
|
|
|
http.Redirect(w, r, fld, http.StatusTemporaryRedirect)
|
|
|
}
|
|
|
return
|
|
|
+ } else if h.isTopLevelRedirectableDomain(domainOnly) {
|
|
|
+ //This is requesting a top level private domain that should be serving root
|
|
|
+ h.proxyRequest(w, r, h.Parent.Root)
|
|
|
} else {
|
|
|
//Validate the redirection target URL
|
|
|
parsedURL, err := url.Parse(h.Parent.RootRoutingOptions.UnsetRuleRedirectTarget)
|
|
@@ -216,18 +219,30 @@ func (h *ProxyHandler) handleAccessRouting(w http.ResponseWriter, r *http.Reques
|
|
|
return false
|
|
|
}
|
|
|
|
|
|
-// GetTopLevelRedirectableDomain returns the toppest level of domain
|
|
|
-// that is redirectable. E.g. a.b.c.example.co.uk will return example.co.uk
|
|
|
-func (h *ProxyHandler) getTopLevelRedirectableDomain(unsetSubdomainHost string) (string, error) {
|
|
|
- parts := strings.Split(unsetSubdomainHost, ".")
|
|
|
+// Return if the given host is already topped (e.g. example.com or example.co.uk) instead of
|
|
|
+// a host with subdomain (e.g. test.example.com)
|
|
|
+func (h *ProxyHandler) isTopLevelRedirectableDomain(requestHost string) bool {
|
|
|
+ parts := strings.Split(requestHost, ".")
|
|
|
if len(parts) > 2 {
|
|
|
//Cases where strange tld is used like .co.uk or .com.hk
|
|
|
_, ok := h.Parent.tldMap[strings.Join(parts[1:], ".")]
|
|
|
if ok {
|
|
|
//Already topped
|
|
|
- return "", errors.New("already at top level domain")
|
|
|
+ return true
|
|
|
}
|
|
|
} else {
|
|
|
+ //Already topped
|
|
|
+ return true
|
|
|
+ }
|
|
|
+
|
|
|
+ return false
|
|
|
+}
|
|
|
+
|
|
|
+// GetTopLevelRedirectableDomain returns the toppest level of domain
|
|
|
+// that is redirectable. E.g. a.b.c.example.co.uk will return example.co.uk
|
|
|
+func (h *ProxyHandler) getTopLevelRedirectableDomain(unsetSubdomainHost string) (string, error) {
|
|
|
+ parts := strings.Split(unsetSubdomainHost, ".")
|
|
|
+ if h.isTopLevelRedirectableDomain(unsetSubdomainHost) {
|
|
|
//Already topped
|
|
|
return "", errors.New("already at top level domain")
|
|
|
}
|