From 93dc0285bc665195d9d43320875129fbb50f03a1 Mon Sep 17 00:00:00 2001 From: Derek McGowan Date: Tue, 14 Jul 2015 14:06:03 -0700 Subject: [PATCH] Add ping endpoint Ping endpoint added so clients can get the list of authentication challenges before making an initial request. Updated MainHandler to return JSON object instead of a string. Signed-off-by: Derek McGowan (github: dmcgowan) --- server/handlers/default.go | 8 ++++++-- server/server.go | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/server/handlers/default.go b/server/handlers/default.go index 9de0c820a7..ac7ff9552a 100644 --- a/server/handlers/default.go +++ b/server/handlers/default.go @@ -23,9 +23,13 @@ import ( // MainHandler is the default handler for the server func MainHandler(ctx context.Context, w http.ResponseWriter, r *http.Request) *errors.HTTPError { if r.Method == "GET" { - err := json.NewEncoder(w).Encode("{}") + _, err := w.Write([]byte("{}")) if err != nil { - w.Write([]byte("{server_error: 'Could not parse error message'}")) + return &errors.HTTPError{ + HTTPStatus: http.StatusInternalServerError, + Code: 9999, + Err: err, + } } } else { //w.WriteHeader(http.StatusNotFound) diff --git a/server/server.go b/server/server.go index ff5a6c2d42..f0c012c85a 100644 --- a/server/server.go +++ b/server/server.go @@ -76,6 +76,7 @@ func Run(ctx context.Context, addr, tlsCertFile, tlsKeyFile string, trust signed r := mux.NewRouter() // TODO (endophage): use correct regexes for image and tag names + r.Methods("GET").Path("/v2/").Handler(hand(handlers.MainHandler)) r.Methods("POST").Path("/v2/{imageName:.*}/_trust/tuf/").Handler(hand(handlers.AtomicUpdateHandler, "push", "pull")) r.Methods("GET").Path("/v2/{imageName:.*}/_trust/tuf/{tufRole:(root|targets|snapshot)}.json").Handler(hand(handlers.GetHandler, "pull")) r.Methods("GET").Path("/v2/{imageName:.*}/_trust/tuf/timestamp.json").Handler(hand(handlers.GetTimestampHandler, "pull"))