From 0156fdb15b6cd6ca45b36fa0f539a6de22b9bbbd Mon Sep 17 00:00:00 2001 From: ZizzyDizzyMC Date: Sun, 21 Feb 2021 21:14:31 -0500 Subject: [PATCH] Update upload.go --- upload.go | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/upload.go b/upload.go index b8c2611..655c188 100644 --- a/upload.go +++ b/upload.go @@ -135,6 +135,11 @@ func uploadPostHandler(c web.C, w http.ResponseWriter, r *http.Request) { func uploadPutHandler(c web.C, w http.ResponseWriter, r *http.Request) { upReq := UploadRequest{} uploadHeaderProcess(r, &upReq) + + defer r.Body.Close() + upReq.filename = c.URLParams["name"] + upReq.src = http.MaxBytesReader(w, r.Body, Config.maxSize) + upReq.srcIp = r.Header.Get("X-Forwarded-For") if len(r.Header.Get("Content-Length")) > 0 { i, err := strconv.ParseInt(r.Header.Get("Content-Length"), 10, 64) @@ -144,11 +149,7 @@ func uploadPutHandler(c web.C, w http.ResponseWriter, r *http.Request) { } } } - - defer r.Body.Close() - upReq.filename = c.URLParams["name"] - upReq.src = http.MaxBytesReader(w, r.Body, Config.maxSize) - upReq.srcIp = r.Header.Get("X-Forwarded-For") + upload, err := processUpload(upReq) if strings.EqualFold("application/json", r.Header.Get("Accept")) { @@ -213,6 +214,15 @@ func uploadRemote(c web.C, w http.ResponseWriter, r *http.Request) { oopsHandler(c, w, r, RespAUTO, "Could not retrieve URL") return } + + upReq.filename = filepath.Base(grabUrl.Path) + upReq.src = http.MaxBytesReader(w, resp.Body, Config.maxSize) + upReq.deleteKey = r.FormValue("deletekey") + upReq.accessKey = r.FormValue(accessKeyParamName) + upReq.randomBarename = r.FormValue("randomize") == "yes" + upReq.expiry = parseExpiry(r.FormValue("expiry")) + upReq.srcIp = r.Header.Get("X-Forwarded-For") + if len(r.Header.Get("Content-Length")) > 0 { i, err := strconv.ParseInt(r.Header.Get("Content-Length"), 10, 64) if err == nil { @@ -222,13 +232,6 @@ func uploadRemote(c web.C, w http.ResponseWriter, r *http.Request) { } } - upReq.filename = filepath.Base(grabUrl.Path) - upReq.src = http.MaxBytesReader(w, resp.Body, Config.maxSize) - upReq.deleteKey = r.FormValue("deletekey") - upReq.accessKey = r.FormValue(accessKeyParamName) - upReq.randomBarename = r.FormValue("randomize") == "yes" - upReq.expiry = parseExpiry(r.FormValue("expiry")) - upReq.srcIp = r.Header.Get("X-Forwarded-For") upload, err := processUpload(upReq) if strings.EqualFold("application/json", r.Header.Get("Accept")) {