diff --git a/common/files.go b/common/files.go index 57372d8b..c7893215 100644 --- a/common/files.go +++ b/common/files.go @@ -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 diff --git a/gen_router.go b/gen_router.go index 16b484f8..8293b34e 100644 --- a/gen_router.go +++ b/gen_router.go @@ -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": diff --git a/public/favicon.ico b/public/favicon.ico new file mode 100644 index 00000000..2ec3a9e0 Binary files /dev/null and b/public/favicon.ico differ diff --git a/router_gen/main.go b/router_gen/main.go index 99545418..f012a495 100644 --- a/router_gen/main.go +++ b/router_gen/main.go @@ -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": diff --git a/routes/misc.go b/routes/misc.go index 01502c10..06c82221 100644 --- a/routes/misc.go +++ b/routes/misc.go @@ -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?