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 <andrea.spacca@gmail.com>
This commit is contained in:
Anirudh Haritas Murali 2022-03-02 17:56:00 +05:30 committed by GitHub
parent 368431fb6b
commit 597554a59e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -299,6 +299,8 @@ func (s *Server) postHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain") w.Header().Set("Content-Type", "text/plain")
responseBody := ""
for _, fheaders := range r.MultipartForm.File { for _, fheaders := range r.MultipartForm.File {
for _, fheader := range fheaders { for _, fheader := range fheaders {
filename := sanitize(fheader.Filename) filename := sanitize(fheader.Filename)
@ -384,9 +386,16 @@ func (s *Server) postHandler(w http.ResponseWriter, r *http.Request) {
filename = url.PathEscape(filename) filename = url.PathEscape(filename)
relativeURL, _ := url.Parse(path.Join(s.proxyPath, token, 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) { func (s *Server) cleanTmpFile(f *os.File) {