mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 14:00:54 +00:00
fix router Put and Delete method when post method with _method
This commit is contained in:
parent
68d4c2c0d8
commit
cb49be7815
18
router.go
18
router.go
@ -575,7 +575,7 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
|
||||
if requestPath == route.pattern {
|
||||
runrouter = route.controllerType
|
||||
findrouter = true
|
||||
runMethod = p.getRunMethod(r.Method, route)
|
||||
runMethod = p.getRunMethod(r.Method, context.Input.Query("_method"), route)
|
||||
break
|
||||
}
|
||||
// pattern /admin url /admin 200 /admin/ 404
|
||||
@ -618,7 +618,7 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
|
||||
runrouter = route.controllerType
|
||||
findrouter = true
|
||||
context.Input.Params = params
|
||||
runMethod = p.getRunMethod(r.Method, route)
|
||||
runMethod = p.getRunMethod(r.Method, context.Input.Query("_method"), route)
|
||||
break
|
||||
}
|
||||
}
|
||||
@ -788,7 +788,7 @@ func (p *ControllerRegistor) getErrorHandler(errorCode string) func(rw http.Resp
|
||||
return handler
|
||||
}
|
||||
|
||||
func (p *ControllerRegistor) getRunMethod(method string, router *controllerInfo) string {
|
||||
func (p *ControllerRegistor) getRunMethod(method, _method string, router *controllerInfo) string {
|
||||
method = strings.ToLower(method)
|
||||
if router.hasMethod {
|
||||
if m, ok := router.methods[method]; ok {
|
||||
@ -796,9 +796,21 @@ func (p *ControllerRegistor) getRunMethod(method string, router *controllerInfo)
|
||||
} else if m, ok = router.methods["*"]; ok {
|
||||
return m
|
||||
} else {
|
||||
if method == "POST" || strings.ToLower(_method) == "put" {
|
||||
return "Put"
|
||||
}
|
||||
if method == "POST" || strings.ToLower(_method) == "delete" {
|
||||
return "Delete"
|
||||
}
|
||||
return strings.Title(method)
|
||||
}
|
||||
} else {
|
||||
if method == "POST" || strings.ToLower(_method) == "put" {
|
||||
return "Put"
|
||||
}
|
||||
if method == "POST" || strings.ToLower(_method) == "delete" {
|
||||
return "Delete"
|
||||
}
|
||||
return strings.Title(method)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user