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

View File

@ -21,9 +21,10 @@ WebHandlers:
Domain: mox.example
PathRegexp: ^/static/
DontRedirectPlainHTTP: true
Compress: true
WebStatic:
# This is run from the http package.
Root: ../testdata/web
Root: ../testdata/webserver
ListFiles: true
ResponseHeaders:
X-Test: mox
@ -35,14 +36,14 @@ WebHandlers:
WebStatic:
StripPrefix: /nolist/
# This is run from the http package.
Root: ../testdata/web/static
Root: ../testdata/webserver/static
-
LogName: httpsredir
Domain: mox.example
PathRegexp: ^/tls/
WebStatic:
# This is run from the http package.
Root: ../testdata/web/static
Root: ../testdata/webserver/static
-
LogName: baseurlonly
Domain: mox.example

View File

@ -1 +1,19 @@
html
when larger than 1kb, it will be transparently compressed.
when larger than 1kb, it will be transparently compressed.
when larger than 1kb, it will be transparently compressed.
when larger than 1kb, it will be transparently compressed.
when larger than 1kb, it will be transparently compressed.
when larger than 1kb, it will be transparently compressed.
when larger than 1kb, it will be transparently compressed.
when larger than 1kb, it will be transparently compressed.
when larger than 1kb, it will be transparently compressed.
when larger than 1kb, it will be transparently compressed.
when larger than 1kb, it will be transparently compressed.
when larger than 1kb, it will be transparently compressed.
when larger than 1kb, it will be transparently compressed.
when larger than 1kb, it will be transparently compressed.
when larger than 1kb, it will be transparently compressed.
when larger than 1kb, it will be transparently compressed.
when larger than 1kb, it will be transparently compressed.
when larger than 1kb, it will be transparently compressed.