mirror of
https://gitee.com/IrisVega/frp.git
synced 2024-11-01 22:31:29 +08:00
vhost: fix a wrong usage of sort.Reverse
This commit is contained in:
parent
c2c9f68a00
commit
cdcc1240ec
@ -148,6 +148,7 @@ func (p *ProxyServer) Start(c *conn.Conn) (err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
log.Info("ProxyName [%s], type http listen for host [%s] location [%s]", p.Name, domain, "")
|
||||||
p.listeners = append(p.listeners, l)
|
p.listeners = append(p.listeners, l)
|
||||||
} else {
|
} else {
|
||||||
for _, location := range p.Locations {
|
for _, location := range p.Locations {
|
||||||
@ -155,6 +156,7 @@ func (p *ProxyServer) Start(c *conn.Conn) (err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
log.Info("ProxyName [%s], type http listen for host [%s] location [%s]", p.Name, domain, location)
|
||||||
p.listeners = append(p.listeners, l)
|
p.listeners = append(p.listeners, l)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -165,6 +167,7 @@ func (p *ProxyServer) Start(c *conn.Conn) (err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
log.Info("ProxyName [%s], type http listen for host [%s] location [%s]", p.Name, p.SubDomain, "")
|
||||||
p.listeners = append(p.listeners, l)
|
p.listeners = append(p.listeners, l)
|
||||||
} else {
|
} else {
|
||||||
for _, location := range p.Locations {
|
for _, location := range p.Locations {
|
||||||
@ -172,6 +175,7 @@ func (p *ProxyServer) Start(c *conn.Conn) (err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
log.Info("ProxyName [%s], type http listen for host [%s] location [%s]", p.Name, p.SubDomain, location)
|
||||||
p.listeners = append(p.listeners, l)
|
p.listeners = append(p.listeners, l)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -182,6 +186,7 @@ func (p *ProxyServer) Start(c *conn.Conn) (err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
log.Info("ProxyName [%s], type https listen for host [%s]", p.Name, domain)
|
||||||
p.listeners = append(p.listeners, l)
|
p.listeners = append(p.listeners, l)
|
||||||
}
|
}
|
||||||
if p.SubDomain != "" {
|
if p.SubDomain != "" {
|
||||||
@ -189,6 +194,7 @@ func (p *ProxyServer) Start(c *conn.Conn) (err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
log.Info("ProxyName [%s], type https listen for host [%s]", p.Name, p.SubDomain)
|
||||||
p.listeners = append(p.listeners, l)
|
p.listeners = append(p.listeners, l)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ func (r *VhostRouters) Add(domain, location string, l *Listener) {
|
|||||||
|
|
||||||
vrs, found := r.RouterByDomain[domain]
|
vrs, found := r.RouterByDomain[domain]
|
||||||
if !found {
|
if !found {
|
||||||
vrs = make([]*VhostRouter, 0)
|
vrs = make([]*VhostRouter, 0, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
vr := &VhostRouter{
|
vr := &VhostRouter{
|
||||||
@ -39,25 +39,25 @@ func (r *VhostRouters) Add(domain, location string, l *Listener) {
|
|||||||
}
|
}
|
||||||
vrs = append(vrs, vr)
|
vrs = append(vrs, vr)
|
||||||
|
|
||||||
sort.Reverse(ByLocation(vrs))
|
sort.Sort(sort.Reverse(ByLocation(vrs)))
|
||||||
r.RouterByDomain[domain] = vrs
|
r.RouterByDomain[domain] = vrs
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *VhostRouters) Del(l *Listener) {
|
func (r *VhostRouters) Del(domain, location string) {
|
||||||
r.mutex.Lock()
|
r.mutex.Lock()
|
||||||
defer r.mutex.Unlock()
|
defer r.mutex.Unlock()
|
||||||
|
|
||||||
vrs, found := r.RouterByDomain[l.name]
|
vrs, found := r.RouterByDomain[domain]
|
||||||
if !found {
|
if !found {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, vr := range vrs {
|
for i, vr := range vrs {
|
||||||
if vr.listener == l {
|
if vr.location == location {
|
||||||
if len(vrs) > i+1 {
|
if len(vrs) > i+1 {
|
||||||
r.RouterByDomain[l.name] = append(vrs[:i], vrs[i+1:]...)
|
r.RouterByDomain[domain] = append(vrs[:i], vrs[i+1:]...)
|
||||||
} else {
|
} else {
|
||||||
r.RouterByDomain[l.name] = vrs[:i]
|
r.RouterByDomain[domain] = vrs[:i]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,6 +63,7 @@ func (v *VhostMuxer) Listen(name, location, rewriteHost, userName, passWord stri
|
|||||||
|
|
||||||
l = &Listener{
|
l = &Listener{
|
||||||
name: name,
|
name: name,
|
||||||
|
location: location,
|
||||||
rewriteHost: rewriteHost,
|
rewriteHost: rewriteHost,
|
||||||
userName: userName,
|
userName: userName,
|
||||||
passWord: passWord,
|
passWord: passWord,
|
||||||
@ -153,6 +154,7 @@ func (v *VhostMuxer) handle(c *conn.Conn) {
|
|||||||
|
|
||||||
type Listener struct {
|
type Listener struct {
|
||||||
name string
|
name string
|
||||||
|
location string
|
||||||
rewriteHost string
|
rewriteHost string
|
||||||
userName string
|
userName string
|
||||||
passWord string
|
passWord string
|
||||||
@ -180,7 +182,7 @@ func (l *Listener) Accept() (*conn.Conn, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *Listener) Close() error {
|
func (l *Listener) Close() error {
|
||||||
l.mux.registryRouter.Del(l)
|
l.mux.registryRouter.Del(l.name, l.location)
|
||||||
close(l.accept)
|
close(l.accept)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user