diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2021-05-30 18:25:11 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-30 18:25:11 +0800 |
commit | effad26c0e7348d27f7fdd1c0cbf120d7558cf67 (patch) | |
tree | f6e4bfa168d1de5adaa40f73c52849a3fb529469 /modules/public/dynamic.go | |
parent | d79c8bc30241c98e044de40aa673138e819f765f (diff) | |
download | gitea-effad26c0e7348d27f7fdd1c0cbf120d7558cf67.tar.gz gitea-effad26c0e7348d27f7fdd1c0cbf120d7558cf67.zip |
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>
Diffstat (limited to 'modules/public/dynamic.go')
-rw-r--r-- | modules/public/dynamic.go | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/modules/public/dynamic.go b/modules/public/dynamic.go index a57b636369..0bfe38bc3f 100644 --- a/modules/public/dynamic.go +++ b/modules/public/dynamic.go @@ -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) } |