aboutsummaryrefslogtreecommitdiff
path: root/fs.go
diff options
context:
space:
mode:
authorAdnan Maolood <[email protected]>2021-04-21 11:41:40 -0400
committerAdnan Maolood <[email protected]>2021-04-21 11:41:40 -0400
commit3bc243dd66a31d6c83ba535ff5957753b1a1730c (patch)
tree53b301858322cd79001b371c6b85146f32a6ba3a /fs.go
parentLoggingMiddleware: Prevent writing empty meta (diff)
downloadgo-gemini-3bc243dd66a31d6c83ba535ff5957753b1a1730c.tar.xz
go-gemini-3bc243dd66a31d6c83ba535ff5957753b1a1730c.zip
fs: Remove ServeContent function
Diffstat (limited to 'fs.go')
-rw-r--r--fs.go24
1 files changed, 5 insertions, 19 deletions
diff --git a/fs.go b/fs.go
index 1a734b5..166ba80 100644
--- a/fs.go
+++ b/fs.go
@@ -33,24 +33,6 @@ func (fs fileServer) ServeGemini(ctx context.Context, w ResponseWriter, r *Reque
serveFile(w, r, fs, path.Clean(r.URL.Path), true)
}
-// ServeContent replies to the request using the content in the
-// provided Reader. The main benefit of ServeContent over io.Copy
-// is that it sets the MIME type of the response.
-//
-// ServeContent tries to deduce the type from name's file extension.
-// The name is otherwise unused; it is never sent in the response.
-func ServeContent(w ResponseWriter, r *Request, name string, content io.Reader) {
- serveContent(w, name, content)
-}
-
-func serveContent(w ResponseWriter, name string, content io.Reader) {
- // Detect mimetype from file extension
- ext := path.Ext(name)
- mimetype := mime.TypeByExtension(ext)
- w.SetMediaType(mimetype)
- io.Copy(w, content)
-}
-
// ServeFile responds to the request with the contents of the named file
// or directory.
//
@@ -171,7 +153,11 @@ func serveFile(w ResponseWriter, r *Request, fsys fs.FS, name string, redirect b
return
}
- serveContent(w, name, f)
+ // Detect mimetype from file extension
+ ext := path.Ext(name)
+ mimetype := mime.TypeByExtension(ext)
+ w.SetMediaType(mimetype)
+ io.Copy(w, f)
}
func dirList(w ResponseWriter, f fs.File) {