Md at debian.org

tales of a debian maintainer

lighttpd and cache validators

Today it has been pointed out to me that lighttpd has an annoying misfeature which makes it not generate the HTTP cache validators (the ETag and Last-Modified headers) when the object requested has no Content-Type, to work around a Firefox misfeature. Since at least one of these headers is needed by HTTP clients to implement caching, this means that these files become uncacheable and everything from wget to apt will fully download them every time.

The default configuration of the lighttpd Debian package does not set a default Content-Type for files without a known extension, so when it is used to serve a Debian mirror it will make files like Packages.gz uncacheable. This configuration fragment fixes it, and also adds a Content-Encoding header to allow transparent decompression by browsers:

$HTTP["host"] == "ftp.it.debian.org" {
  server.document-root = base + "debian/"
  accesslog.filename   = logdir + "debian-access.log"
  server.dir-listing = "enable"
  
  # everything is either already compressed or not worth compressing
  compress.filetype = ( )
  
  $HTTP["url"] =~ "^/debian/(dists|doc|indices|project/experimental)/" {
    $HTTP["url"] =~ "^/debian/dists/.+/images/.+/." { # d-i images/kernels/etc
      mimetype.assign = ( "" => "application/octet-stream" )
    } else $HTTP["url"] =~ "." {
      mimetype.assign = ( "" => "text/plain" )
    }
    # allow transparent decompression by browsers
    $HTTP["url"] =~ "\.gz$" {
      setenv.add-response-header = ("Content-Encoding" => "gzip")
    } else $HTTP["url"] =~ "\.bz2$" {
      setenv.add-response-header = ("Content-Encoding" => "bzip2")
    }
  }
}

About

This is the blog of Marco d'Itri.

S M T W T F S
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30          

See also:

My blogroll:


W3C HTML 4.01
W3C CSS 2.0     

Powered by Bryar.pm.