mirror of
https://github.com/astaxie/beego.git
synced 2024-11-26 05:21:30 +00:00
support copy requestbody
This commit is contained in:
parent
2abe584bc5
commit
7bfb4126d7
1
beego.go
1
beego.go
@ -45,6 +45,7 @@ var (
|
|||||||
HttpServerTimeOut int64
|
HttpServerTimeOut int64
|
||||||
ErrorsShow bool
|
ErrorsShow bool
|
||||||
XSRFKEY string
|
XSRFKEY string
|
||||||
|
CopyRequestBody bool
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -186,6 +186,9 @@ func ParseConfig() (err error) {
|
|||||||
if errorsshow, err := AppConfig.Bool("errorsshow"); err == nil {
|
if errorsshow, err := AppConfig.Bool("errorsshow"); err == nil {
|
||||||
ErrorsShow = errorsshow
|
ErrorsShow = errorsshow
|
||||||
}
|
}
|
||||||
|
if copyrequestbody, err := AppConfig.Bool("copyrequestbody"); err == nil {
|
||||||
|
CopyRequestBody = copyrequestbody
|
||||||
|
}
|
||||||
if xsrfkey := AppConfig.String("xsrfkey"); xsrfkey != "" {
|
if xsrfkey := AppConfig.String("xsrfkey"); xsrfkey != "" {
|
||||||
XSRFKEY = xsrfkey
|
XSRFKEY = xsrfkey
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
type Context struct {
|
type Context struct {
|
||||||
ResponseWriter http.ResponseWriter
|
ResponseWriter http.ResponseWriter
|
||||||
Request *http.Request
|
Request *http.Request
|
||||||
|
RequestBody []byte
|
||||||
Params map[string]string
|
Params map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
18
router.go
18
router.go
@ -1,7 +1,9 @@
|
|||||||
package beego
|
package beego
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
@ -258,6 +260,18 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
|
|||||||
|
|
||||||
requestPath := r.URL.Path
|
requestPath := r.URL.Path
|
||||||
|
|
||||||
|
var requestbody []byte
|
||||||
|
|
||||||
|
if CopyRequestBody {
|
||||||
|
requestbody, _ = ioutil.ReadAll(r.Body)
|
||||||
|
|
||||||
|
r.Body.Close()
|
||||||
|
|
||||||
|
bf := bytes.NewBuffer(requestbody)
|
||||||
|
|
||||||
|
r.Body = ioutil.NopCloser(bf)
|
||||||
|
}
|
||||||
|
|
||||||
r.ParseMultipartForm(MaxMemory)
|
r.ParseMultipartForm(MaxMemory)
|
||||||
|
|
||||||
//user defined Handler
|
//user defined Handler
|
||||||
@ -346,7 +360,7 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
|
|||||||
params[route.params[i]] = match
|
params[route.params[i]] = match
|
||||||
}
|
}
|
||||||
//reassemble query params and add to RawQuery
|
//reassemble query params and add to RawQuery
|
||||||
r.URL.RawQuery = url.Values(values).Encode() + "&" + r.URL.RawQuery
|
r.URL.RawQuery = url.Values(values).Encode()
|
||||||
//r.URL.RawQuery = url.Values(values).Encode()
|
//r.URL.RawQuery = url.Values(values).Encode()
|
||||||
}
|
}
|
||||||
runrouter = route
|
runrouter = route
|
||||||
@ -370,7 +384,7 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
|
|||||||
//call the controller init function
|
//call the controller init function
|
||||||
init := vc.MethodByName("Init")
|
init := vc.MethodByName("Init")
|
||||||
in := make([]reflect.Value, 2)
|
in := make([]reflect.Value, 2)
|
||||||
ct := &Context{ResponseWriter: w, Request: r, Params: params}
|
ct := &Context{ResponseWriter: w, Request: r, Params: params, RequestBody: requestbody}
|
||||||
|
|
||||||
in[0] = reflect.ValueOf(ct)
|
in[0] = reflect.ValueOf(ct)
|
||||||
in[1] = reflect.ValueOf(runrouter.controllerType.Name())
|
in[1] = reflect.ValueOf(runrouter.controllerType.Name())
|
||||||
|
Loading…
Reference in New Issue
Block a user