implement transparent gzip compression in the webserver

we only compress if applicable (content-type indicates likely compressible),
client supports it, response doesn't already have a content-encoding).

for internal handlers, we always enable compression.  for reverse proxied and
static files, compression must be enabled per handler.

for internal & reverse proxy handlers, we do streaming compression at
"bestspeed" quality (probably level 1).

for static files, we have a cache based on mtime with fixed max size, where we
evict based on least recently used. we compress with the default level (more
cpu, better ratio).
This commit is contained in:
Mechiel Lukkien
2023-08-21 21:52:35 +02:00
parent 4c72184b44
commit 9e248860ee
13 changed files with 696 additions and 33 deletions

9
http/atime_bsd.go Normal file
View File

@ -0,0 +1,9 @@
//go:build netbsd || freebsd || darwin
package http
import "syscall"
func statAtime(sys *syscall.Stat_t) int64 {
return int64(sys.Atimespec.Sec)*1000*1000*1000 + int64(sys.Atimespec.Nsec)
}