mirror of https://github.com/fatedier/frp
Addressed Copilot commnets too
parent
4835801e74
commit
760b7f5d96
|
@ -1,4 +1,4 @@
|
||||||
// Copyright 2024 Satyajeet Singh, jeet.0733@gmail.com
|
// Copyright 2025 Satyajeet Singh, jeet.0733@gmail.com
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
// you may not use this file except in compliance with the License.
|
// you may not use this file except in compliance with the License.
|
||||||
|
@ -113,16 +113,13 @@ func (rp *HTTPSReverseProxy) getVhost(domain string) (*Router, bool) {
|
||||||
|
|
||||||
domain = strings.ToLower(domain)
|
domain = strings.ToLower(domain)
|
||||||
|
|
||||||
// First we check the full hostname
|
// Check the full hostname, if not exist, check the wildcard_domain such as *.example.com
|
||||||
// if not exist, then check the wildcard_domain such as *.example.com
|
|
||||||
vr, ok := findRouter(domain)
|
vr, ok := findRouter(domain)
|
||||||
if ok {
|
if ok {
|
||||||
return vr, ok
|
return vr, ok
|
||||||
}
|
}
|
||||||
|
|
||||||
// e.g. domain = test.example.com, try to match wildcard domains.
|
// e.g. domain = test.example.com, try to match wildcard domains. *.example.com, *.com
|
||||||
// *.example.com
|
|
||||||
// *.com
|
|
||||||
domainSplit := strings.Split(domain, ".")
|
domainSplit := strings.Split(domain, ".")
|
||||||
for len(domainSplit) >= 3 {
|
for len(domainSplit) >= 3 {
|
||||||
domainSplit[0] = "*"
|
domainSplit[0] = "*"
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright 2024 Satyajeet Singh, jeet.0733@gmail.com
|
// Copyright 2025 Satyajeet Singh, jeet.0733@gmail.com
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
// you may not use this file except in compliance with the License.
|
// you may not use this file except in compliance with the License.
|
||||||
|
@ -101,7 +101,28 @@ func (g *HTTPSGroup) Register(
|
||||||
defer g.mu.Unlock()
|
defer g.mu.Unlock()
|
||||||
if len(g.createFuncs) == 0 {
|
if len(g.createFuncs) == 0 {
|
||||||
// the first proxy in this group
|
// the first proxy in this group
|
||||||
tmp := routeConfig // copy object
|
// Create a deep copy to avoid shared state
|
||||||
|
tmp := vhost.RouteConfig{
|
||||||
|
Domain: routeConfig.Domain,
|
||||||
|
Location: routeConfig.Location,
|
||||||
|
RewriteHost: routeConfig.RewriteHost,
|
||||||
|
Username: routeConfig.Username,
|
||||||
|
Password: routeConfig.Password,
|
||||||
|
RouteByHTTPUser: routeConfig.RouteByHTTPUser,
|
||||||
|
}
|
||||||
|
// Deep copy maps to avoid shared state
|
||||||
|
if routeConfig.Headers != nil {
|
||||||
|
tmp.Headers = make(map[string]string, len(routeConfig.Headers))
|
||||||
|
for k, v := range routeConfig.Headers {
|
||||||
|
tmp.Headers[k] = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if routeConfig.ResponseHeaders != nil {
|
||||||
|
tmp.ResponseHeaders = make(map[string]string, len(routeConfig.ResponseHeaders))
|
||||||
|
for k, v := range routeConfig.ResponseHeaders {
|
||||||
|
tmp.ResponseHeaders[k] = v
|
||||||
|
}
|
||||||
|
}
|
||||||
tmp.CreateConnFn = g.createConn
|
tmp.CreateConnFn = g.createConn
|
||||||
tmp.ChooseEndpointFn = g.chooseEndpoint
|
tmp.ChooseEndpointFn = g.chooseEndpoint
|
||||||
tmp.CreateConnByEndpointFn = g.createConnByEndpoint
|
tmp.CreateConnByEndpointFn = g.createConnByEndpoint
|
||||||
|
|
|
@ -54,7 +54,7 @@ func NewHTTPSProxy(baseProxy *BaseProxy) Proxy {
|
||||||
|
|
||||||
func (pxy *HTTPSProxy) Run() (remoteAddr string, err error) {
|
func (pxy *HTTPSProxy) Run() (remoteAddr string, err error) {
|
||||||
xl := pxy.xl
|
xl := pxy.xl
|
||||||
routeConfig := vhost.RouteConfig{
|
routeConfig := &vhost.RouteConfig{
|
||||||
CreateConnFn: pxy.GetRealConn,
|
CreateConnFn: pxy.GetRealConn,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,17 +76,19 @@ func (pxy *HTTPSProxy) Run() (remoteAddr string, err error) {
|
||||||
|
|
||||||
// handle group
|
// handle group
|
||||||
if pxy.cfg.LoadBalancer.Group != "" {
|
if pxy.cfg.LoadBalancer.Group != "" {
|
||||||
err = pxy.rc.HTTPSGroupCtl.Register(pxy.name, pxy.cfg.LoadBalancer.Group, pxy.cfg.LoadBalancer.GroupKey, routeConfig)
|
err = pxy.rc.HTTPSGroupCtl.Register(pxy.name, pxy.cfg.LoadBalancer.Group, pxy.cfg.LoadBalancer.GroupKey, *routeConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
pxy.closeFuncs = append(pxy.closeFuncs, func() {
|
pxy.closeFuncs = append(pxy.closeFuncs, func(cfg vhost.RouteConfig) func() {
|
||||||
pxy.rc.HTTPSGroupCtl.UnRegister(pxy.name, pxy.cfg.LoadBalancer.Group, tmpRouteConfig)
|
return func() {
|
||||||
})
|
pxy.rc.HTTPSGroupCtl.UnRegister(pxy.name, pxy.cfg.LoadBalancer.Group, cfg)
|
||||||
|
}
|
||||||
|
}(*tmpRouteConfig))
|
||||||
} else {
|
} else {
|
||||||
// no group - use direct muxer
|
// no group - use direct muxer
|
||||||
l, errRet := pxy.rc.VhostHTTPSMuxer.Listen(pxy.ctx, &routeConfig)
|
l, errRet := pxy.rc.VhostHTTPSMuxer.Listen(pxy.ctx, routeConfig)
|
||||||
if errRet != nil {
|
if errRet != nil {
|
||||||
err = errRet
|
err = errRet
|
||||||
return
|
return
|
||||||
|
@ -106,17 +108,19 @@ func (pxy *HTTPSProxy) Run() (remoteAddr string, err error) {
|
||||||
|
|
||||||
// handle group
|
// handle group
|
||||||
if pxy.cfg.LoadBalancer.Group != "" {
|
if pxy.cfg.LoadBalancer.Group != "" {
|
||||||
err = pxy.rc.HTTPSGroupCtl.Register(pxy.name, pxy.cfg.LoadBalancer.Group, pxy.cfg.LoadBalancer.GroupKey, routeConfig)
|
err = pxy.rc.HTTPSGroupCtl.Register(pxy.name, pxy.cfg.LoadBalancer.Group, pxy.cfg.LoadBalancer.GroupKey, *routeConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
pxy.closeFuncs = append(pxy.closeFuncs, func() {
|
pxy.closeFuncs = append(pxy.closeFuncs, func(cfg vhost.RouteConfig) func() {
|
||||||
pxy.rc.HTTPSGroupCtl.UnRegister(pxy.name, pxy.cfg.LoadBalancer.Group, tmpRouteConfig)
|
return func() {
|
||||||
})
|
pxy.rc.HTTPSGroupCtl.UnRegister(pxy.name, pxy.cfg.LoadBalancer.Group, cfg)
|
||||||
|
}
|
||||||
|
}(*tmpRouteConfig))
|
||||||
} else {
|
} else {
|
||||||
// no group - use direct muxer
|
// no group - use direct muxer
|
||||||
l, errRet := pxy.rc.VhostHTTPSMuxer.Listen(pxy.ctx, &routeConfig)
|
l, errRet := pxy.rc.VhostHTTPSMuxer.Listen(pxy.ctx, routeConfig)
|
||||||
if errRet != nil {
|
if errRet != nil {
|
||||||
err = errRet
|
err = errRet
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue