From 5b18cf09e7643d08f28f0e963c56474eafb35747 Mon Sep 17 00:00:00 2001 From: listeng Date: Mon, 26 Dec 2016 16:49:43 +0800 Subject: [PATCH] Return json data when content-type is "application/json" Before #344, the filer will return json data, and cschiano make a template that render to html. But sometimes need json data, so I add some code will return json data when content-type is "application/json". --- weed/server/filer_server_handlers_read.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/weed/server/filer_server_handlers_read.go b/weed/server/filer_server_handlers_read.go index bf95e37b9..5bd59b23f 100644 --- a/weed/server/filer_server_handlers_read.go +++ b/weed/server/filer_server_handlers_read.go @@ -74,7 +74,12 @@ func (fs *FilerServer) listDirectoryHandler(w http.ResponseWriter, r *http.Reque lastFileName, shouldDisplayLoadMore, } - ui.StatusTpl.Execute(w, args) + + if strings.ToLower(r.Header.Get("Content-Type")) == "application/json" { + writeJsonQuiet(w, r, http.StatusOK, args) + } else { + ui.StatusTpl.Execute(w, args) + } } func (fs *FilerServer) GetOrHeadHandler(w http.ResponseWriter, r *http.Request, isGetMethod bool) {