Просмотр исходного кода

Merge pull request #728 from wunter8/attachment-filename

set attachment filename when download through browser
Philipp C. Heckel 2 лет назад
Родитель
Сommit
8f87e9008b
2 измененных файлов с 4 добавлено и 0 удалено
  1. 1 0
      docs/releases.md
  2. 3 0
      server/server.go

+ 1 - 0
docs/releases.md

@@ -1186,6 +1186,7 @@ and the [ntfy Android app](https://github.com/binwiederhier/ntfy-android/release
 * Make emoji lookup for emails more efficient ([#725](https://github.com/binwiederhier/ntfy/pull/725), thanks to [@adamantike](https://github.com/adamantike))
 * Fix potential subscriber ID clash ([#712](https://github.com/binwiederhier/ntfy/issues/712), thanks to [@peterbourgon](https://github.com/peterbourgon) for reporting, and [@dropdevrahul](https://github.com/dropdevrahul) for fixing)
 * Support for `quoted-printable` in incoming emails ([#719](https://github.com/binwiederhier/ntfy/pull/719), thanks to [@Aerion](https://github.com/Aerion))
+* Attachments with filenames that are downloaded using a browser will now download with the proper filename ([#726](https://github.com/binwiederhier/ntfy/issues/726), thanks to [un99known99](https://github.com/un99known99) for reporting, and [@wunter8](https://github.com/wunter8) for fixing)
 
 ### ntfy Android app v1.16.1 (UNRELEASED)
 

+ 3 - 0
server/server.go

@@ -642,6 +642,9 @@ func (s *Server) handleFile(w http.ResponseWriter, r *http.Request, v *visitor)
 		return err
 	}
 	defer f.Close()
+	if m.Attachment.Name != "" {
+		w.Header().Set("Content-Disposition", "attachment; filename="+strconv.Quote(m.Attachment.Name))
+	}
 	_, err = io.Copy(util.NewContentTypeWriter(w, r.URL.Path), f)
 	return err
 }