You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
As discussed in other issues on this topic, the HTTP 308 code was introduced after mux was written. There are also clients that do not handle HTTP 308 correctly.
Describe the bug
After cleanPath, it writes into header to redirect request
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:
Call:
curl --location --request POST 'http://localhost:8080//user'
to see bugThe text was updated successfully, but these errors were encountered: