Redesign ResponseWriter interface

This commit is contained in:
Adnan Maolood 2021-02-17 13:36:16 -05:00
parent 8543eca416
commit 110c2de6de
4 changed files with 60 additions and 64 deletions

18
fs.go
View File

@ -49,7 +49,7 @@ func serveContent(w ResponseWriter, name string, content io.Reader) {
// Detect mimetype from file extension // Detect mimetype from file extension
ext := path.Ext(name) ext := path.Ext(name)
mimetype := mime.TypeByExtension(ext) mimetype := mime.TypeByExtension(ext)
w.Meta(mimetype) w.MediaType(mimetype)
io.Copy(w, content) io.Copy(w, content)
} }
@ -80,7 +80,7 @@ func ServeFile(w ResponseWriter, r *Request, fsys fs.FS, name string) {
// here and ".." may not be wanted. // here and ".." may not be wanted.
// Note that name might not contain "..", for example if code (still // Note that name might not contain "..", for example if code (still
// incorrectly) used filepath.Join(myDir, r.URL.Path). // incorrectly) used filepath.Join(myDir, r.URL.Path).
w.Header(StatusBadRequest, "invalid URL path") w.WriteHeader(StatusBadRequest, "invalid URL path")
return return
} }
serveFile(w, r, fsys, name, false) serveFile(w, r, fsys, name, false)