diff --git a/CONFIGURATION.md b/CONFIGURATION.md index d4e3dbe..875d690 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -62,6 +62,11 @@ certbot certonly --config-dir /home/www/certs \ Provide the path to the certificate file at `certs/live/$DOMAIN/fullchain.pem` and the private key file at `certs/live/$DOMAIN/privkey.pem` to twins. +### DisableSize + +The size of the response body is included in the media type header by default. +Set this option to `true` to disable this feature. + ### Path #### Resources diff --git a/config.go b/config.go index 44895b5..9d59800 100644 --- a/config.go +++ b/config.go @@ -57,6 +57,8 @@ type serverConfig struct { Hosts map[string]*hostConfig + DisableSize bool + hostname string port int fcgiPools map[string]gofast.ConnFactory diff --git a/server_file.go b/server_file.go index 5a1fc01..8e034ad 100644 --- a/server_file.go +++ b/server_file.go @@ -141,7 +141,12 @@ func serveFile(c net.Conn, request *url.URL, filePath string, listDir bool) { buf := make([]byte, 261) n, _ := file.Read(buf) - // Write header + // Write response header + size := int64(-1) + info, err := file.Stat() + if err == nil { + size = info.Size() + } var mimeType string if strings.HasSuffix(filePath, ".html") && strings.HasSuffix(filePath, ".htm") { mimeType = "text/html; charset=utf-8" @@ -156,7 +161,13 @@ func serveFile(c net.Conn, request *url.URL, filePath string, listDir bool) { if mimeType == "" { mimeType = "text/gemini; charset=utf-8" } - writeHeader(c, statusSuccess, mimeType) + var meta string + if !config.DisableSize && size >= 0 { + meta = fmt.Sprintf("%s; size=%d", mimeType, size) + } else { + meta = mimeType + } + writeHeader(c, statusSuccess, meta) // Write body c.Write(buf[:n])