aboutsummaryrefslogtreecommitdiffstats
path: root/modules/public/static.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2021-05-30 18:25:11 +0800
committerGitHub <noreply@github.com>2021-05-30 18:25:11 +0800
commiteffad26c0e7348d27f7fdd1c0cbf120d7558cf67 (patch)
treef6e4bfa168d1de5adaa40f73c52849a3fb529469 /modules/public/static.go
parentd79c8bc30241c98e044de40aa673138e819f765f (diff)
downloadgitea-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/static.go')
-rw-r--r--modules/public/static.go14
1 files changed, 5 insertions, 9 deletions
diff --git a/modules/public/static.go b/modules/public/static.go
index 36cfdbe44f..827dc2a1e0 100644
--- a/modules/public/static.go
+++ b/modules/public/static.go
@@ -20,12 +20,8 @@ import (
"code.gitea.io/gitea/modules/log"
)
-// Static implements the static handler for serving assets.
-func Static(opts *Options) func(next http.Handler) http.Handler {
- opts.FileSystem = Assets
- // we don't need to pass the directory, because the directory var is only
- // used when in the options there is no FileSystem.
- return opts.staticHandler("")
+func fileSystem(dir string) http.FileSystem {
+ return Assets
}
func Asset(name string) ([]byte, error) {
@@ -59,8 +55,8 @@ func AssetIsDir(name string) (bool, error) {
}
}
-// 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) {
encodings := parseAcceptEncoding(req.Header.Get("Accept-Encoding"))
if encodings["gzip"] {
if cf, ok := fi.(*vfsgen۰CompressedFileInfo); ok {
@@ -76,7 +72,7 @@ func ServeContent(w http.ResponseWriter, req *http.Request, fi os.FileInfo, modt
_, err := rd.Seek(0, io.SeekStart) // rewind to output whole file
if err != nil {
log.Error("rd.Seek error: %v", err)
- http.Error(w, http.StatusText(500), 500)
+ http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
}