Simple S3-like server for development purposes, written in Go

Leverage net/http to allow range requests

HEAD requests of huge files will be a bit more inefficient.

Changed files
+4 -9
+4 -9
server.go
··· 114 114 return 115 115 } 116 116 117 - w.Header().Set("Content-Type", "binary/octet-stream") 118 - w.Header().Set("Content-Length", strconv.FormatInt(fileInfo.Size(), 10)) 119 - w.Header().Set("Last-Modified", fileInfo.ModTime().UTC().Format(http.TimeFormat)) 120 - 121 - if r.Method == http.MethodHead { 122 - return 123 - } 124 - 117 + // NOTE: If the file is huge, we will open it even in HEAD requests, 118 + // which shouldn't be needed - but then using http.ServeContent gets trickier 125 119 file, err := root.Open(path) 126 120 if err != nil { 127 121 http.Error(w, err.Error(), http.StatusInternalServerError) 128 122 } 129 - io.Copy(w, file) 123 + 124 + http.ServeContent(w, r, fileInfo.Name(), fileInfo.ModTime(), file) 130 125 } 131 126 132 127 func (s *server) ls(w http.ResponseWriter, r *http.Request) {