作者 tangxuhui

优化转发逻辑

1 package mobile_client 1 package mobile_client
2 2
3 import ( 3 import (
4 - "bytes"  
5 - "io/ioutil"  
6 "net/http" 4 "net/http"
7 "net/http/httputil" 5 "net/http/httputil"
8 "net/url" 6 "net/url"
@@ -33,10 +31,9 @@ func (controller *ReverseProxyController) SuplusSaleApp() { @@ -33,10 +31,9 @@ func (controller *ReverseProxyController) SuplusSaleApp() {
33 if err != nil { 31 if err != nil {
34 panic(err) 32 panic(err)
35 } 33 }
36 - controller.Ctx.Request.Body = ioutil.NopCloser(bytes.NewReader(controller.Ctx.Input.RequestBody))  
37 controller.Ctx.Request.URL.Path = strings.Replace(controller.Ctx.Request.URL.Path, "/suplus-sale-app", "", 1) 34 controller.Ctx.Request.URL.Path = strings.Replace(controller.Ctx.Request.URL.Path, "/suplus-sale-app", "", 1)
38 targetQuery := target.RawQuery 35 targetQuery := target.RawQuery
39 - director := func(req *http.Request) { 36 + directorFunc := func(req *http.Request) {
40 req.Host = target.Host 37 req.Host = target.Host
41 req.URL.Scheme = target.Scheme 38 req.URL.Scheme = target.Scheme
42 req.URL.Host = target.Host 39 req.URL.Host = target.Host
@@ -51,7 +48,7 @@ func (controller *ReverseProxyController) SuplusSaleApp() { @@ -51,7 +48,7 @@ func (controller *ReverseProxyController) SuplusSaleApp() {
51 req.Header.Set("User-Agent", "") 48 req.Header.Set("User-Agent", "")
52 } 49 }
53 } 50 }
54 - newProxy := &httputil.ReverseProxy{Director: director} 51 + newProxy := &httputil.ReverseProxy{Director: directorFunc}
55 newProxy.ServeHTTP(controller.Ctx.ResponseWriter, controller.Ctx.Request) 52 newProxy.ServeHTTP(controller.Ctx.ResponseWriter, controller.Ctx.Request)
56 } 53 }
57 54