utils/vhost: supprot http authentication

This commit is contained in:
Maodanping
2016-08-29 10:53:02 +08:00
parent 77f207d69a
commit dc5e130d33
10 changed files with 111 additions and 19 deletions

View File

@@ -156,6 +156,16 @@ func LoadConf(confFile string) (err error) {
if ok {
proxyClient.HostHeaderRewrite = tmpStr
}
//http_username
tmpStr, ok = section["http_username"]
if ok {
proxyClient.HttpUserName = tmpStr
}
//http_password
tmpStr, ok = section["http_password"]
if ok {
proxyClient.HttpPassWord = tmpStr
}
}
// privilege_mode

View File

@@ -24,4 +24,6 @@ type BaseConf struct {
PrivilegeToken string
PoolCount int64
HostHeaderRewrite string
HttpUserName string
HttpPassWord string
}

View File

@@ -35,6 +35,8 @@ type ControlReq struct {
RemotePort int64 `json:"remote_port"`
CustomDomains []string `json:"custom_domains, omitempty"`
HostHeaderRewrite string `json:"host_header_rewrite"`
HttpUserName string `json:"http_username"`
HttpPassWord string `json:"http_password"`
Timestamp int64 `json:"timestamp"`
}

View File

@@ -72,6 +72,8 @@ func NewProxyServerFromCtlMsg(req *msg.ControlReq) (p *ProxyServer) {
}
p.CustomDomains = req.CustomDomains
p.HostHeaderRewrite = req.HostHeaderRewrite
p.HttpUserName = req.HttpUserName
p.HttpPassWord = req.HttpPassWord
return
}
@@ -88,7 +90,8 @@ func (p *ProxyServer) Init() {
func (p *ProxyServer) Compare(p2 *ProxyServer) bool {
if p.Name != p2.Name || p.AuthToken != p2.AuthToken || p.Type != p2.Type ||
p.BindAddr != p2.BindAddr || p.ListenPort != p2.ListenPort || p.HostHeaderRewrite != p2.HostHeaderRewrite {
p.BindAddr != p2.BindAddr || p.ListenPort != p2.ListenPort || p.HostHeaderRewrite != p2.HostHeaderRewrite ||
p.HttpUserName != p2.HttpUserName || p.HttpPassWord != p2.HttpPassWord {
return false
}
if len(p.CustomDomains) != len(p2.CustomDomains) {
@@ -122,7 +125,7 @@ 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)
l, err := VhostHttpMuxer.Listen(domain, p.HostHeaderRewrite, p.HttpUserName, p.HttpPassWord)
if err != nil {
return err
}
@@ -130,7 +133,7 @@ func (p *ProxyServer) Start(c *conn.Conn) (err error) {
}
} else if p.Type == "https" {
for _, domain := range p.CustomDomains {
l, err := VhostHttpsMuxer.Listen(domain, p.HostHeaderRewrite)
l, err := VhostHttpsMuxer.Listen(domain, p.HostHeaderRewrite, p.HttpUserName, p.HttpPassWord)
if err != nil {
return err
}