fix router bug: when the request is PUT or DELETE, router can't find the actual …
…route and will throw 404 page to user
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 | ... | ... |
-
Please register or sign in to post a comment