From 2f108714c85f7a5c4af4bc9e63a053c860e77da1 Mon Sep 17 00:00:00 2001 From: luominggang Date: Thu, 27 Dec 2018 09:06:46 +0800 Subject: [PATCH] readable uri to upstream interface name --- cluster/httpCluster.go | 6 +++--- http/httpProxy.go | 4 +--- provider/httpProvider.go | 4 +++- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cluster/httpCluster.go b/cluster/httpCluster.go index 33633a10..b0cf1b14 100644 --- a/cluster/httpCluster.go +++ b/cluster/httpCluster.go @@ -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 @@ -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 { @@ -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 } diff --git a/http/httpProxy.go b/http/httpProxy.go index 8d8a8a4a..9e906af8 100644 --- a/http/httpProxy.go +++ b/http/httpProxy.go @@ -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 } diff --git a/provider/httpProvider.go b/provider/httpProvider.go index 2f3f38fd..6f4ee88a 100644 --- a/provider/httpProvider.go +++ b/provider/httpProvider.go @@ -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)