diff --git a/src/handler/proxyhandler.go b/src/handler/proxyhandler.go index 360be748a76a9bf90b6ed590148acc0ac706448c..b2d57d67ea6f5ce13f8a82b34a00ca174123c89e 100644 --- a/src/handler/proxyhandler.go +++ b/src/handler/proxyhandler.go @@ -3,12 +3,12 @@ package handler import ( "fmt" "github.com/gin-gonic/gin" - "github.com/sirupsen/logrus" "gitlab.wodcloud.com/apaas/apaas-meshproxy/src/client" + "gitlab.wodcloud.com/apaas/apaas-meshproxy/src/tools" "net/http" + "strings" "github.com/vulcand/oxy/forward" - "github.com/vulcand/oxy/testutils" "gitlab.wodcloud.com/apaas/apaas-meshproxy/src/config" ) @@ -24,16 +24,29 @@ func Proxy(c *gin.Context) { c.String(200, "缓存计数失败!") return } - req := c.Request - baseUrl := "http://" + req.Host + req.URL.Path - req.URL = testutils.ParseURI(getProxyURL(req)) - req.RequestURI = getRequestURI(req) - req.Host = req.URL.Host - logrus.Info("************************************") - logrus.Info("* 调用地址:", baseUrl) - logrus.Info("* 转发地址:", req.URL) - logrus.Info("************************************") - fwd.ServeHTTP(c.Writer, req) + var result []byte + var err error + switch strings.ToUpper(config.ProxyConf.Method) { + case "GET": + result, err = tools.ProxySend(c.Request, "GET", config.ProxyConf.Url, "", nil) + } + if err != nil { + c.Error(err) + return + } + + c.Writer.Write(result) + // + //req := c.Request + //baseUrl := "http://" + req.Host + req.URL.Path + //req.URL = testutils.ParseURI(getProxyURL(req)) + //req.RequestURI = getRequestURI(req) + //req.Host = req.URL.Host + //logrus.Info("************************************") + //logrus.Info("* 调用地址:", baseUrl) + //logrus.Info("* 转发地址:", req.URL) + //logrus.Info("************************************") + //fwd.ServeHTTP(c.Writer, req) } func getProxyURL(req *http.Request) string {