How do I create a Path or PathPrefix in Gorilla http framework if the user forces a URI that does not begin with a slash? This causes a direct to whatever the user specifies, e.g.:
# curl -Iv http://testdomain.com --request-target example.com:80
* Added testdomain.com to DNS cache
* Hostname testdomain.com was found in DNS cache
> HEAD example:80 HTTP/1.1
> Host: testdomain.com
> User-Agent: curl/7.79.1
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 301 Moved Permanently
HTTP/1.1 301 Moved Permanently
< Location: example:80
Location: example:80
< Date: Fri, 28 Oct 2022 18:53:03 GMT
Date: Fri, 28 Oct 2022 18:53:03 GMT
<
* Connection #0 to host REDACTED left intact
Currently, it does not match anything in my route setup, yet generates a redirect. Middle-ware is also not catching anything to act on:
func filterMW(next http.Handler) http.Handler {
logrus.Infof("In filterMW")
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
dump, _ := httputil.DumpRequest(r, false)
logrus.Infof("%v", string(dump))
next.ServeHTTP(w, r)
})
}
httpRouter := mux.NewRouter()
httpRouter.Use(filterMW)
Thoughts?
Edit: Updated to include more details!
Nicw Work,
ReplyDeleteI'm Really glad to read your Blog. This Blog is very informative here some informative knowledge from my side to about General Studies Paper 2
Thank You