From 098fc8182509f28dbb05553615936170a501432f Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Sun, 5 Jul 2015 19:19:02 +0100 Subject: [PATCH 1/2] output json status based on 'Accept' header ...instead if having a separate URL. Closes #1063. --- prog/weaver/main.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/prog/weaver/main.go b/prog/weaver/main.go index be5e50ae..717fad47 100644 --- a/prog/weaver/main.go +++ b/prog/weaver/main.go @@ -259,6 +259,11 @@ func handleHTTP(router *weave.Router, httpAddr string, allocator *ipam.Allocator allocator.HandleHTTP(muxRouter, defaultSubnet, docker) } + muxRouter.Methods("GET").Path("/status").Headers("Accept", "application/json").HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + json, _ := router.StatusJSON(version) + w.Write(json) + }) + muxRouter.Methods("GET").Path("/status").HandlerFunc(func(w http.ResponseWriter, r *http.Request) { fmt.Fprintln(w, "weave router", version) fmt.Fprintln(w, router.Status()) @@ -268,11 +273,6 @@ func handleHTTP(router *weave.Router, httpAddr string, allocator *ipam.Allocator } }) - muxRouter.Methods("GET").Path("/status-json").HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - json, _ := router.StatusJSON(version) - w.Write(json) - }) - muxRouter.Methods("POST").Path("/connect").HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if err := r.ParseForm(); err != nil { http.Error(w, fmt.Sprint("unable to parse form: ", err), http.StatusBadRequest) From c8bd47e94829eb1e5dd89797d995badc6386698c Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Sun, 5 Jul 2015 19:25:28 +0100 Subject: [PATCH 2/2] set correct content-type header when returning json status --- prog/weaver/main.go | 1 + 1 file changed, 1 insertion(+) diff --git a/prog/weaver/main.go b/prog/weaver/main.go index 717fad47..4f4b68de 100644 --- a/prog/weaver/main.go +++ b/prog/weaver/main.go @@ -261,6 +261,7 @@ func handleHTTP(router *weave.Router, httpAddr string, allocator *ipam.Allocator muxRouter.Methods("GET").Path("/status").Headers("Accept", "application/json").HandlerFunc(func(w http.ResponseWriter, r *http.Request) { json, _ := router.StatusJSON(version) + w.Header().Set("Content-Type", "application/json") w.Write(json) })