Fixed POST handler
This commit is contained in:
parent
25bcbac05f
commit
e81328c53e
22
server.go
22
server.go
@ -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")
|
body, err := ioutil.ReadAll(r.Body)
|
||||||
|
log.Printf("body: %v", body)
|
||||||
if blob == "" {
|
if err != nil {
|
||||||
body, err := ioutil.ReadAll(r.Body)
|
http.Error(w, "Internal Error", http.StatusInternalServerError)
|
||||||
if err != nil {
|
return
|
||||||
http.Error(w, "Internal Error", http.StatusInternalServerError)
|
|
||||||
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 {
|
||||||
|
Loading…
Reference in New Issue
Block a user