From e81328c53e0fcaf380629c7b92150297558758e6 Mon Sep 17 00:00:00 2001 From: James Mills Date: Thu, 17 May 2018 14:51:39 -0700 Subject: [PATCH] Fixed POST handler --- server.go | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/server.go b/server.go index 96a27a9..fe22801 100644 --- a/server.go +++ b/server.go @@ -116,28 +116,20 @@ func (s *Server) PasteHandler() httprouter.Handle { return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) { s.counters.Inc("n_paste") - blob := r.FormValue("blob") - - if blob == "" { - body, err := ioutil.ReadAll(r.Body) - if err != nil { - http.Error(w, "Internal Error", http.StatusInternalServerError) - return - } - blob = string(body) + body, err := ioutil.ReadAll(r.Body) + log.Printf("body: %v", body) + if err != nil { + http.Error(w, "Internal Error", http.StatusInternalServerError) + return } - if blob == "" { - blob = r.URL.Query().Get("blob") - } - - if blob == "" { + if len(body) == 0 { http.Error(w, "Bad Request", http.StatusBadRequest) return } uuid := shortuuid.NewWithNamespace(s.config.fqdn) - s.store.Set(uuid, blob, cache.DefaultExpiration) + s.store.Set(uuid, string(body), cache.DefaultExpiration) u, err := url.Parse(fmt.Sprintf("./p/%s", uuid)) if err != nil {