support the configure of url in "http" section

This commit is contained in:
XueBing
2016-12-18 22:40:58 +08:00
Unverified
parent 47db75e921
commit edf4bc431d
10 changed files with 227 additions and 106 deletions
+9 -5
View File
@@ -296,6 +296,12 @@ func loadProxyConf(confFile string) (proxyServers map[string]*ProxyServer, err e
} else {
return proxyServers, fmt.Errorf("Parse conf error: proxy [%s] custom_domains must be set when type equals http", proxyServer.Name)
}
//location
locStr, loc_ok := section["custom_location"]
if loc_ok {
proxyServer.Locations = strings.Split(locStr, ",")
}
} else if proxyServer.Type == "https" {
// for https
proxyServer.ListenPort = VhostHttpsPort
@@ -318,9 +324,8 @@ func loadProxyConf(confFile string) (proxyServers map[string]*ProxyServer, err e
}
// set metric statistics of all proxies
for name, p := range proxyServers {
metric.SetProxyInfo(name, p.Type, p.BindAddr, p.UseEncryption, p.UseGzip,
p.PrivilegeMode, p.CustomDomains, p.ListenPort)
for _, p := range proxyServers {
metric.SetProxyInfo(*p.ProxyServerConf)
}
return proxyServers, nil
}
@@ -381,8 +386,7 @@ func CreateProxy(s *ProxyServer) error {
}
}
ProxyServers[s.Name] = s
metric.SetProxyInfo(s.Name, s.Type, s.BindAddr, s.UseEncryption, s.UseGzip,
s.PrivilegeMode, s.CustomDomains, s.ListenPort)
metric.SetProxyInfo(*s.ProxyServerConf)
s.Init()
return nil
}
+17 -25
View File
@@ -33,13 +33,9 @@ type Listener interface {
}
type ProxyServer struct {
config.BaseConf
BindAddr string
ListenPort int64
CustomDomains []string
*config.ProxyServerConf
Status int64
CtlConn *conn.Conn // control connection with frpc
CtlConn *conn.Conn `json:"-"` // control connection with frpc
listeners []Listener // accept new connection from remote users
ctlMsgChan chan int64 // every time accept a new user conn, put "1" to the channel
workConnChan chan *conn.Conn // get new work conns from control goroutine
@@ -48,8 +44,9 @@ type ProxyServer struct {
}
func NewProxyServer() (p *ProxyServer) {
psc := &config.ProxyServerConf{CustomDomains: make([]string, 0)}
p = &ProxyServer{
CustomDomains: make([]string, 0),
ProxyServerConf: psc,
}
return p
}
@@ -101,6 +98,15 @@ func (p *ProxyServer) Compare(p2 *ProxyServer) bool {
return false
}
}
if len(p.Locations) != len(p2.Locations) {
return false
}
for i, _ := range p.Locations {
if p.Locations[i] != p2.Locations[i] {
return false
}
}
return true
}
@@ -123,27 +129,13 @@ func (p *ProxyServer) Start(c *conn.Conn) (err error) {
}
p.listeners = append(p.listeners, l)
} else if p.Type == "http" {
for _, domain := range p.CustomDomains {
l, err := VhostHttpMuxer.Listen(domain, p.HostHeaderRewrite, p.HttpUserName, p.HttpPassWord)
if err != nil {
return err
}
ls := VhostHttpMuxer.Listen(p.ProxyServerConf)
for _, l := range ls {
p.listeners = append(p.listeners, l)
}
if p.SubDomain != "" {
l, err := VhostHttpMuxer.Listen(p.SubDomain, p.HostHeaderRewrite, p.HttpUserName, p.HttpPassWord)
if err != nil {
return err
}
p.listeners = append(p.listeners, l)
}
} else if p.Type == "https" {
for _, domain := range p.CustomDomains {
l, err := VhostHttpsMuxer.Listen(domain, p.HostHeaderRewrite, p.HttpUserName, p.HttpPassWord)
if err != nil {
return err
}
ls := VhostHttpsMuxer.Listen(p.ProxyServerConf)
for _, l := range ls {
p.listeners = append(p.listeners, l)
}
}