Skip to content

Commit 4d27b43

Browse files
committed
Fix bug
1 parent 19bf03c commit 4d27b43

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

modules/public/static.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ import (
1010
"compress/gzip"
1111
"io"
1212
"io/ioutil"
13-
"log"
1413
"mime"
1514
"net/http"
1615
"path/filepath"
1716
"time"
17+
18+
"code.gitea.io/gitea/modules/log"
1819
)
1920

2021
// Static implements the macaron static handler for serving assets.
@@ -60,9 +61,9 @@ func AssetIsDir(name string) (bool, error) {
6061
func ServeContent(w http.ResponseWriter, req *http.Request, name string, modtime time.Time, content io.ReadSeeker) {
6162
encodings := parseAcceptEncoding(req.Header.Get("Accept-Encoding"))
6263
if encodings["gzip"] {
63-
if rd, ok := f.(*vfsgen۰CompressedFile); ok {
64+
if rd, ok := content.(*vfsgen۰CompressedFile); ok {
6465
w.Header().Set("Content-Encoding", "gzip")
65-
ctype := mime.TypeByExtension(filepath.Ext(fi.Name()))
66+
ctype := mime.TypeByExtension(filepath.Ext(name))
6667
if ctype == "" {
6768
// read a chunk to decide between utf-8 text and binary
6869
var buf [512]byte
@@ -71,16 +72,17 @@ func ServeContent(w http.ResponseWriter, req *http.Request, name string, modtime
7172
ctype = http.DetectContentType(buf[:n])
7273
_, err := rd.Seek(0, io.SeekStart) // rewind to output whole file
7374
if err != nil {
74-
log.Printf("rd.Seek error: %v\n", err)
75-
return false
75+
log.Error("rd.Seek error: %v", err)
76+
http.Error(w, http.StatusText(500), 500)
77+
return
7678
}
7779
}
7880
w.Header().Set("Content-Type", ctype)
79-
http.ServeContent(w, req, file, fi.ModTime(), rd)
80-
return true
81+
http.ServeContent(w, req, name, modtime, rd)
82+
return
8183
}
8284
}
8385

84-
http.ServeContent(w, req, file, fi.ModTime(), f)
85-
return true
86+
http.ServeContent(w, req, name, modtime, content)
87+
return
8688
}

0 commit comments

Comments
 (0)