cb49be78 by astaxie

fix router Put and Delete method when post method with _method

1 parent 68d4c2c0
Showing 1 changed file with 15 additions and 3 deletions
...@@ -575,7 +575,7 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) ...@@ -575,7 +575,7 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
575 if requestPath == route.pattern { 575 if requestPath == route.pattern {
576 runrouter = route.controllerType 576 runrouter = route.controllerType
577 findrouter = true 577 findrouter = true
578 runMethod = p.getRunMethod(r.Method, route) 578 runMethod = p.getRunMethod(r.Method, context.Input.Query("_method"), route)
579 break 579 break
580 } 580 }
581 // pattern /admin url /admin 200 /admin/ 404 581 // pattern /admin url /admin 200 /admin/ 404
...@@ -618,7 +618,7 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) ...@@ -618,7 +618,7 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
618 runrouter = route.controllerType 618 runrouter = route.controllerType
619 findrouter = true 619 findrouter = true
620 context.Input.Params = params 620 context.Input.Params = params
621 runMethod = p.getRunMethod(r.Method, route) 621 runMethod = p.getRunMethod(r.Method, context.Input.Query("_method"), route)
622 break 622 break
623 } 623 }
624 } 624 }
...@@ -788,7 +788,7 @@ func (p *ControllerRegistor) getErrorHandler(errorCode string) func(rw http.Resp ...@@ -788,7 +788,7 @@ func (p *ControllerRegistor) getErrorHandler(errorCode string) func(rw http.Resp
788 return handler 788 return handler
789 } 789 }
790 790
791 func (p *ControllerRegistor) getRunMethod(method string, router *controllerInfo) string { 791 func (p *ControllerRegistor) getRunMethod(method, _method string, router *controllerInfo) string {
792 method = strings.ToLower(method) 792 method = strings.ToLower(method)
793 if router.hasMethod { 793 if router.hasMethod {
794 if m, ok := router.methods[method]; ok { 794 if m, ok := router.methods[method]; ok {
...@@ -796,9 +796,21 @@ func (p *ControllerRegistor) getRunMethod(method string, router *controllerInfo) ...@@ -796,9 +796,21 @@ func (p *ControllerRegistor) getRunMethod(method string, router *controllerInfo)
796 } else if m, ok = router.methods["*"]; ok { 796 } else if m, ok = router.methods["*"]; ok {
797 return m 797 return m
798 } else { 798 } else {
799 if method == "POST" || strings.ToLower(_method) == "put" {
800 return "Put"
801 }
802 if method == "POST" || strings.ToLower(_method) == "delete" {
803 return "Delete"
804 }
799 return strings.Title(method) 805 return strings.Title(method)
800 } 806 }
801 } else { 807 } else {
808 if method == "POST" || strings.ToLower(_method) == "put" {
809 return "Put"
810 }
811 if method == "POST" || strings.ToLower(_method) == "delete" {
812 return "Delete"
813 }
802 return strings.Title(method) 814 return strings.Title(method)
803 } 815 }
804 } 816 }
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!