-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Closed
Description
Describe the bug
After cleanPath, it writes into header to redirect request
if p := cleanPath(path); p != path {
// Added 3 lines (Philip Schlump) - It was dropping the query string and #whatever from query.
// This matches with fix in go 1.2 r.c. 4 for same problem. Go Issue:
// http://code.google.com/p/go/issues/detail?id=5252
url := *req.URL
url.Path = p
p = url.String()
w.Header().Set("Location", p)
w.WriteHeader(http.StatusMovedPermanently)
return
}
But it doesn't set method, so redirection calls GET method by default, and error will occur if I call POST method with path like http://my.domain//api
Code example:
package main
import (
"log"
"net/http"
"fmt"
"github.com/gorilla/mux"
)
func main() {
r := mux.NewRouter()
r.Methods("GET").Path("/user/{userID:[0-9]+}").HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
fmt.Println("GET Call")
})
r.Methods("POST").Path("/user").HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
fmt.Println("POST Call")
})
http.Handle("/", r)
panic(http.ListenAndServe(":8080", nil))
}
Call: curl --location --request POST 'http://localhost:8080//user' to see bug
Reactions are currently unavailable