This commit is contained in:
Toby Chui 2024-12-22 13:25:16 +08:00
parent 49555c1191
commit 992dd231f2
6 changed files with 9 additions and 7 deletions

View File

@ -142,7 +142,7 @@ func (h *ProxyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
/* /*
handleRootRouting handleRootRouting
This function handle root routing situations where there are no subdomain This function handle root routing (aka default sites) situations where there are no subdomain
, vdir or special routing rule matches the requested URI. , vdir or special routing rule matches the requested URI.
Once entered this routing segment, the root routing options will take over Once entered this routing segment, the root routing options will take over
@ -222,12 +222,10 @@ func (h *ProxyHandler) handleRootRouting(w http.ResponseWriter, r *http.Request)
h.Parent.logRequest(r, false, 444, "root-noresponse", domainOnly) h.Parent.logRequest(r, false, 444, "root-noresponse", domainOnly)
hijacker, ok := w.(http.Hijacker) hijacker, ok := w.(http.Hijacker)
if !ok { if !ok {
http.Error(w, "Hijacking not supported", http.StatusInternalServerError)
return return
} }
conn, _, err := hijacker.Hijack() conn, _, err := hijacker.Hijack()
if err != nil { if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return return
} }
conn.Close() conn.Close()

View File

@ -264,5 +264,6 @@ func (ep *ProxyEndpoint) Remove() error {
// use prepare -> remove -> add if you change anything in the endpoint // use prepare -> remove -> add if you change anything in the endpoint
// that effects the proxy routing src / dest // that effects the proxy routing src / dest
func (ep *ProxyEndpoint) UpdateToRuntime() { func (ep *ProxyEndpoint) UpdateToRuntime() {
ep.parent.ProxyEndpoints.Store(ep.RootOrMatchingDomain, ep) lookupHostname := strings.ToLower(ep.RootOrMatchingDomain)
ep.parent.ProxyEndpoints.Store(lookupHostname, ep)
} }

View File

@ -35,6 +35,7 @@ func (router *Router) getTargetProxyEndpointFromRequestURI(requestURI string) *P
// Get the proxy endpoint from hostname, which might includes checking of wildcard certificates // Get the proxy endpoint from hostname, which might includes checking of wildcard certificates
func (router *Router) getProxyEndpointFromHostname(hostname string) *ProxyEndpoint { func (router *Router) getProxyEndpointFromHostname(hostname string) *ProxyEndpoint {
var targetSubdomainEndpoint *ProxyEndpoint = nil var targetSubdomainEndpoint *ProxyEndpoint = nil
hostname = strings.ToLower(hostname)
ep, ok := router.ProxyEndpoints.Load(hostname) ep, ok := router.ProxyEndpoints.Load(hostname)
if ok { if ok {
//Exact hit //Exact hit

View File

@ -70,9 +70,10 @@ func (router *Router) PrepareProxyRoute(endpoint *ProxyEndpoint) (*ProxyEndpoint
// Add Proxy Route to current runtime. Call to PrepareProxyRoute before adding to runtime // Add Proxy Route to current runtime. Call to PrepareProxyRoute before adding to runtime
func (router *Router) AddProxyRouteToRuntime(endpoint *ProxyEndpoint) error { func (router *Router) AddProxyRouteToRuntime(endpoint *ProxyEndpoint) error {
lookupHostname := strings.ToLower(endpoint.RootOrMatchingDomain)
if len(endpoint.ActiveOrigins) == 0 { if len(endpoint.ActiveOrigins) == 0 {
//There are no active origins. No need to check for ready //There are no active origins. No need to check for ready
router.ProxyEndpoints.Store(endpoint.RootOrMatchingDomain, endpoint) router.ProxyEndpoints.Store(lookupHostname, endpoint)
return nil return nil
} }
if !router.loadBalancer.UpstreamsReady(endpoint.ActiveOrigins) { if !router.loadBalancer.UpstreamsReady(endpoint.ActiveOrigins) {
@ -80,7 +81,7 @@ func (router *Router) AddProxyRouteToRuntime(endpoint *ProxyEndpoint) error {
return errors.New("proxy endpoint not ready. Use PrepareProxyRoute before adding to runtime") return errors.New("proxy endpoint not ready. Use PrepareProxyRoute before adding to runtime")
} }
// Push record into running subdomain endpoints // Push record into running subdomain endpoints
router.ProxyEndpoints.Store(endpoint.RootOrMatchingDomain, endpoint) router.ProxyEndpoints.Store(lookupHostname, endpoint)
return nil return nil
} }

View File

@ -923,6 +923,7 @@ func ReverseProxyListDetail(w http.ResponseWriter, r *http.Request) {
utils.SendErrorResponse(w, "epname not defined") utils.SendErrorResponse(w, "epname not defined")
return return
} }
epname = strings.ToLower(strings.TrimSpace(epname))
endpointRaw, ok := dynamicProxyRouter.ProxyEndpoints.Load(epname) endpointRaw, ok := dynamicProxyRouter.ProxyEndpoints.Load(epname)
if !ok { if !ok {
utils.SendErrorResponse(w, "proxy rule not found") utils.SendErrorResponse(w, "proxy rule not found")

View File

@ -41,7 +41,7 @@
<div class="ui radio defaultsite checkbox"> <div class="ui radio defaultsite checkbox">
<input type="radio" name="defaultsiteOption" value="closeresp"> <input type="radio" name="defaultsiteOption" value="closeresp">
<label>Close Connection<br> <label>Close Connection<br>
<small>Close the connection without any response</small> <small>Close the connection without any response or in TLS mode, send an empty response</small>
</label> </label>
</div> </div>
</div> </div>