Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
Adds required download param to be set when downloading plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
jcooklin committed Oct 2, 2015
1 parent 8e39e8f commit 4fdfa51
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions mgmt/rest/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 4fdfa51

Please sign in to comment.