-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Strict Slashes don't work #472
Comments
Please upgrade to the latest version of mux - I'm not able to replicate
this on the latest version.
(5bbbb is from early 2018).
➜ curl -svL localhost:8080/health/ 2>&1 | rg '< HTTP'
< HTTP/1.1 200 OK
➜ curl -svL localhost:8080/health 2>&1 | rg '< HTTP'
< HTTP/1.1 301 Moved Permanently
< HTTP/1.1 200 OK
…On Fri, May 3, 2019 at 9:20 AM Dustin Morgan ***@***.***> wrote:
*What version of Go are you running?* (Paste the output of go version)
github.com/gorilla/mux v0.0.0-20180107155708-5bbbb5b2b572
*What version of gorilla/mux are you at?* (Paste the output of git
rev-parse HEAD inside $GOPATH/src/github.com/gorilla/mux)
github.com/gorilla/mux v0.0.0-20180107155708-5bbbb5b2b572
*Describe your problem* (and what you have tried so far)
rtr = mux.NewRouter().StrictSlash(true)
rtr.HandleFunc("/health/", health)
opening /health will always result in 404 instead of 301
*Paste a minimal, runnable, reproduction of your issue below* (use
backticks to format it)
package main
import (
"github.com/gorilla/mux"
"net/http"
"encoding/json"
)
func main() {
rtr := mux.NewRouter().StrictSlash(true)
rtr.HandleFunc("/health/", health)
s := &http.Server{
Addr: ":8080",
Handler: rtr,
}
s.ListenAndServe()
}
func health(w http.ResponseWriter, r *http.Request) {
status := struct {
Status string
}{
"OK",
}
w.Header().Set("Content-Type", "application/json")
j, _ := json.Marshal(status)
w.Write(j)
}
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#472>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAAEQ4BODA74DC5DP57UTSLPTRQ3ZANCNFSM4HKVH3FQ>
.
|
I'm usually configure my handle func more like this:
and, when I call |
I have the same problem....
|
Can you show how you're testing this?
…On Mon, May 20, 2019 at 8:06 AM Fernando Campos Schelb < ***@***.***> wrote:
I have the same problem....
router := mux.NewRouter().StrictSlash(true)
s := router.PathPrefix("/v0").Subrouter().StrictSlash(true)
s.HandleFunc("/health/", HealthCheckHandler).Methods("GET")
s.HandleFunc("/tags/", CreateTagHandler).Methods("POST")
s.HandleFunc("/tags/", GetTagsHandler).Methods("GET")
1. The StrictSlash in subrouter dont work
2. When I post in tags without the final '/', the return is the GET.
Its bizarre...
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#472?email_source=notifications&email_token=AAAEQ4DI3EH77CYGPMFUT6DPWK45XA5CNFSM4HKVH3F2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODVZEAOQ#issuecomment-494026810>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAAEQ4BVCUDYLGQPSUVNF43PWK45XANCNFSM4HKVH3FQ>
.
|
I made a post in Postman... [POST] http://localhost:6000/v0/tags and the body in response is the same body for the GET |
From the docs
This may explain why some of you are hitting the GET handler instead of the POST when using strict slash. |
So I updated to the latest version of Mux and the issue persists
|
It's not a _bug_ - this is the HTTP spec.
Returning a 301/302 to a POST/PUT/DELETE (any non-idempotent method) will
cause the client to retry as a GET, for safety.
Middleware can modify this to return a 307/308 instead, if need be.
…On Wed, Jun 19, 2019 at 11:57 AM Dustin Morgan ***@***.***> wrote:
So I updated to the latest version of Mux and the issue persists
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#472?email_source=notifications&email_token=AAAEQ4DHQOHCVG6WHOZCOXDP3J6R3A5CNFSM4HKVH3F2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODYC2NLI#issuecomment-503686829>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAAEQ4AOP4BJQB35UJ3R4V3P3J6R3ANCNFSM4HKVH3FQ>
.
|
See my comments - #451 (comment) and this full example of middleware. |
What version of Go are you running? (Paste the output of
go version
)go version go1.12.5 darwin/amd64
What version of gorilla/mux are you at? (Paste the output of
git rev-parse HEAD
inside$GOPATH/src/github.com/gorilla/mux
)github.com/gorilla/mux v1.7.2
Describe your problem (and what you have tried so far)
rtr = mux.NewRouter().StrictSlash(true)
rtr.HandleFunc("/health/", health)
opening
/health
will always result in 404 instead of 301Paste a minimal, runnable, reproduction of your issue below (use backticks to format it)
The text was updated successfully, but these errors were encountered: