Add a simple letter favicon.
Disable Gzip for favicons, it doesn't make them smaller anyway. Eliminate an allocation for static files. Fixes #59
This commit is contained in:
parent
cb8e83ec79
commit
ed68c6fc04
@ -32,6 +32,7 @@ type SFile struct {
|
||||
Pos int64
|
||||
Length int64
|
||||
GzipLength int64
|
||||
StrGzipLength string
|
||||
Mimetype string
|
||||
Info os.FileInfo
|
||||
FormattedModTime string
|
||||
@ -239,7 +240,7 @@ func (list SFileList) JSTmplInit() error {
|
||||
hasher.Write(data)
|
||||
checksum := hex.EncodeToString(hasher.Sum(nil))
|
||||
|
||||
list.Set("/static/"+path, SFile{data, gzipData, checksum,path + "?h=" + checksum, 0, int64(len(data)), int64(len(gzipData)), mime.TypeByExtension(ext), f, f.ModTime().UTC().Format(http.TimeFormat)})
|
||||
list.Set("/static/"+path, SFile{data, gzipData, checksum,path + "?h=" + checksum, 0, int64(len(data)), int64(len(gzipData)),strconv.Itoa(len(gzipData)), mime.TypeByExtension(ext), f, f.ModTime().UTC().Format(http.TimeFormat)})
|
||||
|
||||
DebugLogf("Added the '%s' static file.", path)
|
||||
return nil
|
||||
@ -284,7 +285,7 @@ func (list SFileList) Init() error {
|
||||
}
|
||||
}
|
||||
|
||||
list.Set("/static/"+path, SFile{data, gzipData, checksum,path + "?h=" + checksum, 0, int64(len(data)), int64(len(gzipData)), mimetype, f, f.ModTime().UTC().Format(http.TimeFormat)})
|
||||
list.Set("/static/"+path, SFile{data, gzipData, checksum,path + "?h=" + checksum, 0, int64(len(data)), int64(len(gzipData)),strconv.Itoa(len(gzipData)), mimetype, f, f.ModTime().UTC().Format(http.TimeFormat)})
|
||||
|
||||
DebugLogf("Added the '%s' static file.", path)
|
||||
return nil
|
||||
@ -317,7 +318,7 @@ func (list SFileList) Add(path string, prefix string) error {
|
||||
hasher.Write(data)
|
||||
checksum := hex.EncodeToString(hasher.Sum(nil))
|
||||
|
||||
list.Set("/static"+path, SFile{data, gzipData, checksum,path + "?h=" + checksum, 0, int64(len(data)), int64(len(gzipData)), mime.TypeByExtension(ext), f, f.ModTime().UTC().Format(http.TimeFormat)})
|
||||
list.Set("/static"+path, SFile{data, gzipData, checksum,path + "?h=" + checksum, 0, int64(len(data)), int64(len(gzipData)),strconv.Itoa(len(gzipData)), mime.TypeByExtension(ext), f, f.ModTime().UTC().Format(http.TimeFormat)})
|
||||
|
||||
DebugLogf("Added the '%s' static file", path)
|
||||
return nil
|
||||
|
@ -2290,8 +2290,9 @@ func (r *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, user c
|
||||
gzw, ok := w.(c.GzipResponseWriter)
|
||||
if ok {
|
||||
w = gzw.ResponseWriter
|
||||
w.Header().Del("Content-Type")
|
||||
w.Header().Del("Content-Encoding")
|
||||
h := w.Header()
|
||||
h.Del("Content-Type")
|
||||
h.Del("Content-Encoding")
|
||||
}
|
||||
counters.RouteViewCounter.Bump(142)
|
||||
req.URL.Path += extraData
|
||||
@ -2306,8 +2307,14 @@ func (r *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, user c
|
||||
counters.RouteViewCounter.Bump(144)
|
||||
return routes.RobotsTxt(w,req)
|
||||
case "favicon.ico":
|
||||
req.URL.Path = "/static"+req.URL.Path+extraData
|
||||
//log.Print("req.URL.Path: ",req.URL.Path)
|
||||
gzw, ok := w.(c.GzipResponseWriter)
|
||||
if ok {
|
||||
w = gzw.ResponseWriter
|
||||
h := w.Header()
|
||||
h.Del("Content-Type")
|
||||
h.Del("Content-Encoding")
|
||||
}
|
||||
req.URL.Path = "/static/favicon.ico"
|
||||
routes.StaticFile(w,req)
|
||||
return nil
|
||||
case "opensearch.xml":
|
||||
|
BIN
public/favicon.ico
Normal file
BIN
public/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
@ -816,8 +816,9 @@ func (r *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, user c
|
||||
gzw, ok := w.(c.GzipResponseWriter)
|
||||
if ok {
|
||||
w = gzw.ResponseWriter
|
||||
w.Header().Del("Content-Type")
|
||||
w.Header().Del("Content-Encoding")
|
||||
h := w.Header()
|
||||
h.Del("Content-Type")
|
||||
h.Del("Content-Encoding")
|
||||
}
|
||||
counters.RouteViewCounter.Bump({{index .AllRouteMap "routes.UploadedFile" }})
|
||||
req.URL.Path += extraData
|
||||
@ -832,8 +833,14 @@ func (r *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, user c
|
||||
counters.RouteViewCounter.Bump({{index .AllRouteMap "routes.RobotsTxt"}})
|
||||
return routes.RobotsTxt(w,req)
|
||||
case "favicon.ico":
|
||||
req.URL.Path = "/static"+req.URL.Path+extraData
|
||||
//log.Print("req.URL.Path: ",req.URL.Path)
|
||||
gzw, ok := w.(c.GzipResponseWriter)
|
||||
if ok {
|
||||
w = gzw.ResponseWriter
|
||||
h := w.Header()
|
||||
h.Del("Content-Type")
|
||||
h.Del("Content-Encoding")
|
||||
}
|
||||
req.URL.Path = "/static/favicon.ico"
|
||||
routes.StaticFile(w,req)
|
||||
return nil
|
||||
case "opensearch.xml":
|
||||
|
@ -20,7 +20,7 @@ var cacheControlMaxAgeWeek = "max-age=" + strconv.Itoa(int(c.Week)) // TODO: Mak
|
||||
func StaticFile(w http.ResponseWriter, r *http.Request) {
|
||||
file, ok := c.StaticFiles.Get(r.URL.Path)
|
||||
if !ok {
|
||||
c.DebugLogf("Failed to find '%s'", r.URL.Path) // TODO: Use MicroNotFound? Might be better than the unneccessary overhead of sprintf
|
||||
//c.DebugLogf("Failed to find '%s'", r.URL.Path) // TODO: Use MicroNotFound? Might be better than the unneccessary overhead of sprintf
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
@ -43,7 +43,7 @@ func StaticFile(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
if strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") && file.GzipLength > 0 {
|
||||
h.Set("Content-Encoding", "gzip")
|
||||
h.Set("Content-Length", strconv.FormatInt(file.GzipLength, 10))
|
||||
h.Set("Content-Length", file.StrGzipLength)
|
||||
io.Copy(w, bytes.NewReader(file.GzipData)) // Use w.Write instead?
|
||||
} else {
|
||||
h.Set("Content-Length", strconv.FormatInt(file.Length, 10)) // Avoid doing a type conversion every time?
|
||||
|
Loading…
Reference in New Issue
Block a user