From 597554a59eb873cbf11eb9e8e62e77acd6a94822 Mon Sep 17 00:00:00 2001 From: Anirudh Haritas Murali <49116134+anihm136@users.noreply.github.com> Date: Wed, 2 Mar 2022 17:56:00 +0530 Subject: [PATCH] Add X-Url-Delete-* headers to POST handler (#435) * Add X-Url-Delete-* headers to POST handler * Remove token from header * Fix writing of headers * Handle error returned by Write * Update handlers.go Co-authored-by: Andrea Spacca --- server/handlers.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/server/handlers.go b/server/handlers.go index eafc522..0eec166 100644 --- a/server/handlers.go +++ b/server/handlers.go @@ -299,6 +299,8 @@ func (s *Server) postHandler(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/plain") + responseBody := "" + for _, fheaders := range r.MultipartForm.File { for _, fheader := range fheaders { filename := sanitize(fheader.Filename) @@ -384,9 +386,16 @@ func (s *Server) postHandler(w http.ResponseWriter, r *http.Request) { filename = url.PathEscape(filename) relativeURL, _ := url.Parse(path.Join(s.proxyPath, token, filename)) - _, _ = w.Write([]byte(getURL(r, s.proxyPort).ResolveReference(relativeURL).String())) + deleteURL, _ := url.Parse(path.Join(s.proxyPath, token, filename, metadata.DeletionToken)) + w.Header().Add("X-Url-Delete", resolveURL(r, deleteURL, s.proxyPort)) + responseBody += fmt.Sprintln(getURL(r, s.proxyPort).ResolveReference(relativeURL).String()) } } + _, err := w.Write([]byte(responseBody)) + if err != nil { + s.logger.Printf("%s", err.Error()) + http.Error(w, err.Error(), http.StatusInternalServerError) + } } func (s *Server) cleanTmpFile(f *os.File) {