Skip to content

Commit

Permalink
add default domain for http mesh support reverse proxy default domain…
Browse files Browse the repository at this point in the history
… handle,

this maybe not a generic usage
  • Loading branch information
luominggang committed Dec 26, 2018
1 parent 4f53b86 commit ec03609
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ func (a *Agent) StartMotanAgent() {
a.initAgentURL()
a.initStatus()
a.initClusters()
a.startServerAgent()
a.initHTTPClusters()
a.startHTTPAgent()
a.startServerAgent()
a.configurer = NewDynamicConfigurer(a)
go a.startMServer()
go a.registerAgent()
Expand Down Expand Up @@ -517,6 +517,7 @@ func getClusterKey(group, version, protocol, path string) string {
}

func initLog(logdir string) {
// TODO: remove after a better handle
if logdir == "stdout" {
return
}
Expand Down
8 changes: 7 additions & 1 deletion server/httpProxyServer.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type HTTPProxyServer struct {
httpClient *fasthttp.Client
deny []string
keepalive bool
defaultDomain string
}

func NewHTTPProxyServer(url *core.URL) *HTTPProxyServer {
Expand All @@ -46,6 +47,7 @@ func (s *HTTPProxyServer) Open(block bool, proxy bool, clusterGetter HTTPCluster
os.Unsetenv("https_proxy")
s.clusterGetter = clusterGetter
s.keepalive, _ = strconv.ParseBool(s.url.GetParam("httpProxyKeepalive", "true"))
s.defaultDomain = s.url.GetParam("httpProxyDefaultDomain", "")
s.deny = append(s.deny, "127.0.0.1:"+s.url.GetPortStr())
s.deny = append(s.deny, "localhost:"+s.url.GetPortStr())
s.deny = append(s.deny, core.GetLocalIP()+":"+s.url.GetPortStr())
Expand Down Expand Up @@ -109,7 +111,11 @@ func (s *HTTPProxyServer) Open(block bool, proxy bool, clusterGetter HTTPCluster
}

host, _, _ := net.SplitHostPort(hostAndPort)
if httpCluster := s.clusterGetter.GetHTTPCluster(host); httpCluster != nil {
httpCluster := s.clusterGetter.GetHTTPCluster(host)
if httpCluster == nil && s.defaultDomain != "" {
httpCluster = s.clusterGetter.GetHTTPCluster(s.defaultDomain)
}
if httpCluster != nil {
if service, ok := httpCluster.CanServe(string(ctx.Path())); ok {
s.doHTTPRpcProxy(ctx, httpCluster, service)
return
Expand Down

0 comments on commit ec03609

Please sign in to comment.