Commit 0c108240 authored by leitao.zhang's avatar leitao.zhang

Merge branch 'dev' into dev-ysgz

parents 81fa533c 9997acc4
......@@ -77,6 +77,15 @@ func Proxy(c *gin.Context) {
//如果是静态文件
if CheckStaticFile(c.Request.URL.Path) {
host := getHost(proxyData.ReqUrl)
//var prefix string
//if apiId == "" {
// prefix= fmt.Sprintf("%s/%s/service/%s/%s/", config.Prefix, config.MeshId,applyId,apiId)
//}else {
// prefix= fmt.Sprintf("%s/%s/service/%s/", config.Prefix, config.MeshId,applyId)
//}
//
//staticPath:= strings.ReplaceAll(c.Request.URL.Path,prefix,"")
fwd, _ := forward.New(forward.PassHostHeader(false))
c.Request.URL = testutils.ParseURI(fmt.Sprintf("%s%s", host, c.Request.URL.Path))
c.Request.RequestURI = getRequestURI(c.Request)
......@@ -86,7 +95,7 @@ func Proxy(c *gin.Context) {
roundTripper := http.DefaultTransport.(*http.Transport)
//roundTripper.ForceAttemptHTTP2 = false
roundTripper.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
f, err := forward.New(forward.PassHostHeader(false), forward.RoundTripper(roundTripper), forward.ResponseModifier(func(resp *http.Response) error {
forwarder, err := forward.New(forward.PassHostHeader(false), forward.RoundTripper(roundTripper), forward.ResponseModifier(func(resp *http.Response) error {
respbody, err1 := ioutil.ReadAll(resp.Body)
if err1 != nil {
log.Println(err1)
......@@ -148,15 +157,25 @@ func Proxy(c *gin.Context) {
return nil
}))
if err != nil {
c.JSON(500, errors.New("请求失败"))
return
}
reqURL := testutils.ParseURI(proxyData.ReqUrl)
if reqURL.RawQuery == "" {
reqURL.RawQuery = c.Request.URL.RawQuery
} else {
if c.Request.URL.RawQuery != "" {
reqURL.RawQuery += "&" + c.Request.URL.RawQuery
}
}
c.Request.URL = testutils.ParseURI(proxyData.ReqUrl)
c.Request.URL = reqURL
fmt.Println("c.Request.URL-------", c.Request.URL)
c.Request.RequestURI = getRequestURI(c.Request)
c.Request.RequestURI = reqURL.RequestURI()
fmt.Println("c.Request-------", c.Request)
c.Request.Host = getHost(proxyData.ReqUrl)
fmt.Println("proxyData.RealUrl-------", proxyData.ReqUrl)
f.ServeHTTP(c.Writer, c.Request)
forwarder.ServeHTTP(c.Writer, c.Request)
}
}
......@@ -169,26 +188,12 @@ func CheckStaticFile(path string) bool {
return false
}
func getProxyURL(proxyData model.ProxyData, req *http.Request) string {
realPath := proxyData.ReqUrl
rawQuery := req.URL.RawQuery
var result = ""
if rawQuery == "" {
if proxyData.DataServiceType1 == 6 {
result = realPath + "?f=json"
} else {
result = realPath
}
} else {
result = realPath + "?" + rawQuery
if proxyData.DataServiceType1 == 6 && !strings.Contains(rawQuery, "f=json") {
result = result + "&f=json"
}
}
return result
}
func getRequestURI(req *http.Request) string {
//requestURI, _ := url.ParseRequestURI(req.RequestURI)
//
//requestURI.RawQuery
path := req.URL.Path
rawQuery := req.URL.RawQuery
var result = ""
......
......@@ -18,7 +18,7 @@ import (
var (
argPort = pflag.Int("port", 8011, "")
argPrefix = pflag.String("prefix", "/bgmesh/fiddler", "")
meshId = pflag.String("meshId", "133", "")
meshId = pflag.String("meshId", "461", "")
redisUrl = pflag.String("redisUrl", "redis://apaas-redis:6379", "")
redisTag = pflag.String("redisTag", "apaas-mesh-proxy", "")
confPath = pflag.String("confPath", "/app/config/proxy.json", "")
......@@ -33,6 +33,7 @@ func main() {
server()
}
//打包
func server() error {
config.Prefix = *argPrefix
handler := router.Load(ginrus.Ginrus(logrus.StandardLogger(), time.RFC3339, true))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment