Fixed POST handler

This commit is contained in:
James Mills 2018-05-17 14:51:39 -07:00
parent 25bcbac05f
commit e81328c53e
No known key found for this signature in database
GPG Key ID: AC4C014F1440EBD6

View File

@ -116,28 +116,20 @@ func (s *Server) PasteHandler() httprouter.Handle {
return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) { return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
s.counters.Inc("n_paste") s.counters.Inc("n_paste")
blob := r.FormValue("blob")
if blob == "" {
body, err := ioutil.ReadAll(r.Body) body, err := ioutil.ReadAll(r.Body)
log.Printf("body: %v", body)
if err != nil { if err != nil {
http.Error(w, "Internal Error", http.StatusInternalServerError) http.Error(w, "Internal Error", http.StatusInternalServerError)
return return
} }
blob = string(body)
}
if blob == "" { if len(body) == 0 {
blob = r.URL.Query().Get("blob")
}
if blob == "" {
http.Error(w, "Bad Request", http.StatusBadRequest) http.Error(w, "Bad Request", http.StatusBadRequest)
return return
} }
uuid := shortuuid.NewWithNamespace(s.config.fqdn) 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)) u, err := url.Parse(fmt.Sprintf("./p/%s", uuid))
if err != nil { if err != nil {