github.com/rsc/buffalo@v0.11.1/method_override.go (about)

     1  package buffalo
     2  
     3  import (
     4  	"net/http"
     5  
     6  	"github.com/markbates/going/defaults"
     7  )
     8  
     9  // MethodOverride is the default implementation for the
    10  // Options#MethodOverride. By default it will look for a form value
    11  // name `_method` and change the request method if that is
    12  // present and the original request is of type "POST". This is
    13  // added automatically when using `New` Buffalo, unless
    14  // an alternative is defined in the Options.
    15  func MethodOverride(res http.ResponseWriter, req *http.Request) {
    16  	if req.Method == "POST" {
    17  		req.Method = defaults.String(req.FormValue("_method"), "POST")
    18  		req.Form.Del("_method")
    19  		req.PostForm.Del("_method")
    20  	}
    21  }