From 8671c4d2207c81286a67968fc4ffbd6c16d58224 Mon Sep 17 00:00:00 2001 From: Las Zenow Date: Thu, 10 Dec 2020 15:43:18 +0000 Subject: [PATCH] Use http.ServeContet to be able to continue downloads - Closes: #59 --- lib/storage/storage.go | 1 + lib/trantor.go | 11 +---------- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/lib/storage/storage.go b/lib/storage/storage.go index 2ccbe95..0746474 100644 --- a/lib/storage/storage.go +++ b/lib/storage/storage.go @@ -15,6 +15,7 @@ type Store interface { type File interface { io.ReadCloser io.ReaderAt + io.Seeker Stat() (fi os.FileInfo, err error) } diff --git a/lib/trantor.go b/lib/trantor.go index 2d7b3d0..583b409 100644 --- a/lib/trantor.go +++ b/lib/trantor.go @@ -1,12 +1,9 @@ package trantor import ( - "time" - log "github.com/cihub/seelog" "fmt" - "io" "net/http" "path" "strings" @@ -115,14 +112,8 @@ func downloadHandler(h handler) { } defer f.Close() - headers := h.w.Header() - headers["Content-Type"] = []string{"application/epub+zip"} - headers["Content-Disposition"] = []string{fmt.Sprintf("attachment; filename=\"%s - %s.epub\"", strings.Join(book.Authors, ", "), book.Title)} - headers["Content-Length"] = []string{fmt.Sprint(book.FileSize)} - headers["Last-Modified"] = []string{fmt.Sprint(book.UploadDate.Format(time.RFC1123))} addCacheControlHeader(h.w, false) - - io.Copy(h.w, f) + http.ServeContent(h.w, h.r, fmt.Sprintf("%s - %s.epub", strings.Join(book.Authors, ", "), book.Title), book.UploadDate, f) } type indexData struct {