···114114 return
115115 }
116116117117- w.Header().Set("Content-Type", "binary/octet-stream")
118118- w.Header().Set("Content-Length", strconv.FormatInt(fileInfo.Size(), 10))
119119- w.Header().Set("Last-Modified", fileInfo.ModTime().UTC().Format(http.TimeFormat))
120120-121121- if r.Method == http.MethodHead {
122122- return
123123- }
124124-117117+ // NOTE: If the file is huge, we will open it even in HEAD requests,
118118+ // which shouldn't be needed - but then using http.ServeContent gets trickier
125119 file, err := root.Open(path)
126120 if err != nil {
127121 http.Error(w, err.Error(), http.StatusInternalServerError)
128122 }
129129- io.Copy(w, file)
123123+124124+ http.ServeContent(w, r, fileInfo.Name(), fileInfo.ModTime(), file)
130125}
131126132127func (s *server) ls(w http.ResponseWriter, r *http.Request) {