From 26fbd00b4f727e3aeedb616de9e1745b14a1cabd Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Sun, 18 Mar 2018 16:26:58 +0000 Subject: [PATCH] serve restic: don't buffer the JSON output in memory for the list command --- cmd/serve/restic/restic.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/cmd/serve/restic/restic.go b/cmd/serve/restic/restic.go index 044cc4178..0b1a170d9 100644 --- a/cmd/serve/restic/restic.go +++ b/cmd/serve/restic/restic.go @@ -434,17 +434,14 @@ func (s *server) listObjects(w http.ResponseWriter, r *http.Request, remote stri } } - data, err := json.Marshal(ls) + w.Header().Set("Content-Type", "application/vnd.x.restic.rest.v2") + enc := json.NewEncoder(w) + err = enc.Encode(ls) if err != nil { - fs.Errorf(remote, "list marshal failed: %v", err) + fs.Errorf(remote, "failed to write list: %v", err) http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } - // fs.Debugf(remote, "ls result = %s", data) - - w.Header().Set("Content-Type", "application/vnd.x.restic.rest.v2") - - _, _ = w.Write(data) } // createRepo creates repository directories.