Rework /report handler to pull format from URL
Otherwise test 150 would fail - Gorilla mux was not handling a newline in the format parameter. This way you also get a better error if you have an error in the parameter - instead of a 404.
This commit is contained in:
1 parent
847046a225
commit
672c770dbe
1 file changed
+7
-2
+7
-2
@@ -329,7 +329,7 @@ func HandleHTTP(muxRouter *mux.Router, version string, router *weave.NetworkRout
|
||||
w.Write(json)
|
||||
})
|
||||
|
||||
muxRouter.Methods("GET").Path("/report").Queries("format", "{format}").HandlerFunc(
|
||||
muxRouter.Methods("GET").Path("/report").HandlerFunc(
|
||||
func(w http.ResponseWriter, r *http.Request) {
|
||||
funcs := template.FuncMap{
|
||||
"json": func(v interface{}) string {
|
||||
@@ -337,7 +337,12 @@ func HandleHTTP(muxRouter *mux.Router, version string, router *weave.NetworkRout
|
||||
return string(a)
|
||||
},
|
||||
}
|
||||
formatTemplate, err := template.New("format").Funcs(funcs).Parse(mux.Vars(r)["format"])
|
||||
format, ok := r.URL.Query()["format"]
|
||||
if !ok || len(format) != 1 {
|
||||
http.Error(w, "error: must supply one format parameter", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
formatTemplate, err := template.New("format").Funcs(funcs).Parse(format[0])
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
|
||||
Reference in new issue
Block a user