Skip to content

Commit

Permalink
readable uri to upstream interface name
Browse files Browse the repository at this point in the history
  • Loading branch information
luominggang committed Dec 27, 2018
1 parent ec03609 commit 2f10871
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions cluster/httpCluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func newClusterHolder(url *core.URL, context *core.Context, extFactory core.Exte
type HTTPCluster struct {
url *core.URL
// for get the service from uri
serviceDiscover http.ServiceDiscover
uriConverter http.URIConverter
proxy bool
upstreamClusters map[string]*clusterHolder
lock sync.RWMutex
Expand Down Expand Up @@ -95,7 +95,7 @@ func NewHTTPCluster(url *core.URL, proxy bool, context *core.Context, extFactory
}
}
c.upstreamClusters = make(map[string]*clusterHolder, 16)
c.serviceDiscover = http.NewLocationMatcherFromContext(domain, context)
c.uriConverter = http.NewLocationMatcherFromContext(domain, context)
preload := core.TrimSplit(url.GetParam(HTTPProxyPreloadKey, ""), ",")
// TODO: find service by location then do warm up
for _, service := range preload {
Expand All @@ -108,7 +108,7 @@ func NewHTTPCluster(url *core.URL, proxy bool, context *core.Context, extFactory
}

func (c *HTTPCluster) CanServe(uri string) (string, bool) {
service := c.serviceDiscover.URIToServiceName(uri)
service := c.uriConverter.URIToServiceName(uri)
if service == "" {
return "", false
}
Expand Down
4 changes: 1 addition & 3 deletions http/httpProxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ func PatternSplit(s string, pattern *regexp.Regexp) []string {
return strings
}

// ServiceDiscover discover which service to use
type ServiceDiscover interface {
// DiscoverService get the service(upstream) by http uri, return empty string if not found
type URIConverter interface {
URIToServiceName(uri string) string
}

Expand Down
4 changes: 3 additions & 1 deletion provider/httpProvider.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,9 @@ func (h *HTTPProvider) Call(request motan.Request) motan.Response {
httpReq.URI().SetPath(rewritePath)
httpReq.Header.Del("Connection")
httpReq.Header.Set("X-Forwarded-For", ip)
httpReq.BodyWriter().Write(bodyBytes)
if len(bodyBytes) != 0 {
httpReq.BodyWriter().Write(bodyBytes)
}
err := h.fastClient.Do(httpReq, httpRes)
if err != nil {
fillExceptionWithCode(resp, http.StatusBadGateway, t, err)
Expand Down

0 comments on commit 2f10871

Please sign in to comment.