fa128100 by WithGJR

fix router bug: when the request is PUT or DELETE, router can't find the actual …

…route and will throw 404 page to user
1 parent f9e991b5
Showing 1 changed file with 15 additions and 1 deletions
...@@ -648,7 +648,21 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) ...@@ -648,7 +648,21 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
648 } 648 }
649 649
650 if !findrouter { 650 if !findrouter {
651 if t, ok := p.routers[r.Method]; ok { 651 http_method := ""
652
653 if r.Method == "POST" && context.Input.Query("_method") == "PUT" {
654 http_method = "PUT"
655 }
656
657 if r.Method == "POST" && context.Input.Query("_method") == "DELETE" {
658 http_method = "DELETE"
659 }
660
661 if http_method != "PUT" && http_method != "DELETE" {
662 http_method = r.Method
663 }
664
665 if t, ok := p.routers[http_method]; ok {
652 runObject, p := t.Match(urlPath) 666 runObject, p := t.Match(urlPath)
653 if r, ok := runObject.(*controllerInfo); ok { 667 if r, ok := runObject.(*controllerInfo); ok {
654 routerInfo = r 668 routerInfo = r
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!