From 4fdfa51ca4073fe593c4cf8fd418a7f334e98fe7 Mon Sep 17 00:00:00 2001 From: Joel Cooklin Date: Fri, 2 Oct 2015 07:54:40 -0700 Subject: [PATCH] Adds required download param to be set when downloading plugin --- mgmt/rest/plugin.go | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/mgmt/rest/plugin.go b/mgmt/rest/plugin.go index 9ae04b1fd..205a65ff7 100644 --- a/mgmt/rest/plugin.go +++ b/mgmt/rest/plugin.go @@ -291,24 +291,27 @@ func (s *Server) getPlugin(w http.ResponseWriter, r *http.Request, p httprouter. return } - b, err := ioutil.ReadFile(plugin.PluginPath()) - if err != nil { - f["plugin-path"] = plugin.PluginPath() - pe := perror.New(err, f) - respond(500, rbody.FromPulseError(pe), w) - return - } + rd := r.FormValue("download") + d, _ := strconv.ParseBool(rd) + if d { + b, err := ioutil.ReadFile(plugin.PluginPath()) + if err != nil { + f["plugin-path"] = plugin.PluginPath() + pe := perror.New(err, f) + respond(500, rbody.FromPulseError(pe), w) + return + } - w.Header().Set("Content-Encoding", "gzip") - gz := gzip.NewWriter(w) - defer gz.Close() - _, err = gz.Write(b) - if err != nil { - f["plugin-path"] = plugin.PluginPath() - pe := perror.New(err, f) - respond(500, rbody.FromPulseError(pe), w) + w.Header().Set("Content-Encoding", "gzip") + gz := gzip.NewWriter(w) + defer gz.Close() + _, err = gz.Write(b) + if err != nil { + f["plugin-path"] = plugin.PluginPath() + pe := perror.New(err, f) + respond(500, rbody.FromPulseError(pe), w) + return + } return } - - // w.WriteHeader(200) }