From 134f7e1cb59b7c1bd4f2eadfebe7f65da1264988 Mon Sep 17 00:00:00 2001 From: Rasmus Dahlberg Date: Fri, 23 Oct 2020 18:37:37 +0200 Subject: added start on get-anchors code path --- handler.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'handler.go') diff --git a/handler.go b/handler.go index 27b2fd9..42f9e23 100644 --- a/handler.go +++ b/handler.go @@ -120,9 +120,20 @@ func getEntries(ctx context.Context, i *instance, w http.ResponseWriter, r *http } // getAnchors provides a list of configured trust anchors -func getAnchors(ctx context.Context, i *instance, w http.ResponseWriter, r *http.Request) (int, error) { +func getAnchors(_ context.Context, i *instance, w http.ResponseWriter, _ *http.Request) (int, error) { glog.Info("in getAnchors") - return http.StatusOK, nil // TODO + data := NewGetAnchorsResponse(i.anchorsPool.RawCertificates()) + json, err := json.Marshal(&data) + if err != nil { + return http.StatusInternalServerError, fmt.Errorf("failed json-encoding GetAnchorsResponse: %v", err) + } + + w.Header().Set("Content-Type", "application/json") + _, err = w.Write(json) + if err != nil { + return http.StatusInternalServerError, fmt.Errorf("failed writing get-anchors response: %v", err) + } + return http.StatusOK, nil } // getProofByHash provides an inclusion proof based on a given leaf hash -- cgit v1.2.3