mirror of
https://github.com/dutchcoders/transfer.sh.git
synced 2024-12-26 12:20:19 +01:00
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:
parent
368431fb6b
commit
597554a59e
1 changed files with 10 additions and 1 deletions
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue