mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-14 05:52:43 +00:00
Improve assets handler middleware (#15961)
* Use route to serve assets but not middleware * Fix build error with bindata tag * convert path to absolute * fix build * reduce function stack * Add tests for assets * Remove test for assets because they are not generated * Use a http function to serve assets * Still use middleware to serve assets then less middleware stack for assets * Move serveContent to original position * remove unnecessary blank line change * Fix bug for /assets* requests * clean code Co-authored-by: zeripath <art27@cantab.net>
This commit is contained in:
parent
d79c8bc302
commit
effad26c0e
6 changed files with 108 additions and 167 deletions
|
@ -13,12 +13,11 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
// Static implements the static handler for serving assets.
|
||||
func Static(opts *Options) func(next http.Handler) http.Handler {
|
||||
return opts.staticHandler(opts.Directory)
|
||||
func fileSystem(dir string) http.FileSystem {
|
||||
return http.Dir(dir)
|
||||
}
|
||||
|
||||
// ServeContent serve http content
|
||||
func ServeContent(w http.ResponseWriter, req *http.Request, fi os.FileInfo, modtime time.Time, content io.ReadSeeker) {
|
||||
// serveContent serve http content
|
||||
func serveContent(w http.ResponseWriter, req *http.Request, fi os.FileInfo, modtime time.Time, content io.ReadSeeker) {
|
||||
http.ServeContent(w, req, fi.Name(), modtime, content)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue