diff --git a/example/httpserver/proxy/main.go b/example/httpserver/proxy/main.go index b8d35cc79..023d423d1 100644 --- a/example/httpserver/proxy/main.go +++ b/example/httpserver/proxy/main.go @@ -44,6 +44,7 @@ func StartServer2() { ) r.Request.URL.Path = proxyToPath g.Log().Infof(r.Context(), `server2:"%s" -> server1:"%s"`, originalPath, proxyToPath) + r.MakeBodyRepeatableRead(false) proxy.ServeHTTP(r.Response.Writer.RawWriter(), r.Request) }) s.SetPort(PortOfServer2) diff --git a/net/ghttp/ghttp_request_param.go b/net/ghttp/ghttp_request_param.go index dc4898612..aba1667e8 100644 --- a/net/ghttp/ghttp_request_param.go +++ b/net/ghttp/ghttp_request_param.go @@ -154,12 +154,12 @@ func (r *Request) Get(key string, def ...interface{}) *gvar.Var { // It can be called multiple times retrieving the same body content. func (r *Request) GetBody() []byte { if r.bodyContent == nil { - r.bodyContent = r.makeBodyRepeatableRead(true) + r.bodyContent = r.MakeBodyRepeatableRead(true) } return r.bodyContent } -func (r *Request) makeBodyRepeatableRead(repeatableRead bool) []byte { +func (r *Request) MakeBodyRepeatableRead(repeatableRead bool) []byte { if r.bodyContent == nil { var err error if r.bodyContent, err = ioutil.ReadAll(r.Body); err != nil { @@ -268,8 +268,8 @@ func (r *Request) parseForm() { return } if contentType := r.Header.Get("Content-Type"); contentType != "" { - // Mark the request body content can be read just once next time. - r.makeBodyRepeatableRead(false) + r.MakeBodyRepeatableRead(true) + var err error if gstr.Contains(contentType, "multipart/") { // multipart/form-data, multipart/mixed