Skip to content

Commit

Permalink
Support files that are not io.ReadSeekers
Browse files Browse the repository at this point in the history
  • Loading branch information
benbjohnson committed Dec 9, 2021
1 parent 2b51fa0 commit a56766a
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion hashfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"os"
"path"
"regexp"
"strconv"
"strings"
"sync"
)
Expand Down Expand Up @@ -192,5 +193,17 @@ func (h *fsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}

// Flush header and write content.
http.ServeContent(w, r, filename, fi.ModTime(), f.(io.ReadSeeker))
switch f := f.(type) {
case io.ReadSeeker:
http.ServeContent(w, r, filename, fi.ModTime(), f.(io.ReadSeeker))
default:
// Set content length.
w.Header().Set("Content-Length", strconv.FormatInt(fi.Size(), 10))

// Flush header and write content.
w.WriteHeader(http.StatusOK)
if r.Method != "HEAD" {
io.Copy(w, f)
}
}
}

0 comments on commit a56766a

Please sign in to comment.