Use http.ServeContet to be able to continue downloads

- Closes: #59
This commit is contained in:
Las Zenow 2020-12-10 15:43:18 +00:00
parent 32b546a212
commit 8671c4d220
2 changed files with 2 additions and 10 deletions

View file

@ -15,6 +15,7 @@ type Store interface {
type File interface {
io.ReadCloser
io.ReaderAt
io.Seeker
Stat() (fi os.FileInfo, err error)
}

View file

@ -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 {