Skip to content

Commit

Permalink
inline canServeCompressed() in serveFileMaybeBr()
Browse files Browse the repository at this point in the history
  • Loading branch information
kjk committed Jan 27, 2022
1 parent 376da72 commit eb74a6a
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions httputil/servefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TryServeFileFromURL(w http.ResponseWriter, r *http.Request, urlPath string,
}
}

if r != nil && opts.ServeCompressed && canServeCompressed(path) {
if r != nil && opts.ServeCompressed {
if serveFileMaybeBr(w, r, path) {
return true
}
Expand All @@ -78,16 +78,17 @@ func TryServeFileFromURL(w http.ResponseWriter, r *http.Request, urlPath string,
return true
}

func canServeCompressed(path string) bool {
func serveFileMaybeBr(w http.ResponseWriter, r *http.Request, path string) bool {
ext := strings.ToLower(filepath.Ext(path))
switch ext {
case ".html", ".txt", ".css", ".js", ".xml":
return true
case ".html", ".txt", ".css", ".js", ".xml", ".svg":
// no-op those we serve compressed
default:
// other formats, e.g. png, should not be served compressed
// fmt.Printf("serveFileMaybeBr: skipping because '%s' not served as br because '%s' should not be served compressed\n", path, ext)
return false
}
return false
}

func serveFileMaybeBr(w http.ResponseWriter, r *http.Request, path string) bool {
if r == nil {
return false
}
Expand Down

0 comments on commit eb74a6a

Please sign in to comment.