diff --git a/PROPOSALS.md b/PROPOSALS.md index 9a7dde4..1a8f3cd 100644 --- a/PROPOSALS.md +++ b/PROPOSALS.md @@ -15,16 +15,6 @@ These additions are backwards-compatible as specified in [RFC 2045](https://tool The terms MAY, SHOULD and SHOULD NOT are defined in [RFC 2119](https://tools.ietf.org/html/rfc2119). -# Size - -Gemini servers SHOULD include the size (in bytes) of the response body when the -request is successful. Clients SHOULD utilize this information when downloading -files to indicate progress. - -``` -20 text/gemini; charset=utf-8; size=1108 -``` - # Cache Gemini servers MAY include a duration (in seconds) which a client SHOULD cache @@ -42,3 +32,13 @@ Do not cache: ``` 20 text/gemini; charset=utf-8; cache=0 ``` + +# Size + +Gemini servers SHOULD include the size (in bytes) of the response body when the +request is successful. Clients SHOULD utilize this information when downloading +files to indicate progress. + +``` +20 text/gemini; charset=utf-8; size=1108 +``` diff --git a/config.go b/config.go index 12af4c5..54154e6 100644 --- a/config.go +++ b/config.go @@ -38,13 +38,14 @@ type pathConfig struct { Type string // Cache duration - Cache int64 `default:"-1965"` + Cache string // FastCGI server address FastCGI string - r *regexp.Regexp - cmd []string + r *regexp.Regexp + cmd []string + cache int64 } type hostConfig struct { @@ -69,6 +70,8 @@ type serverConfig struct { fcgiPools map[string]gofast.ConnFactory } +const cacheUnset = -1965 + var config *serverConfig func readconfig(configPath string) error { @@ -139,6 +142,14 @@ func readconfig(configPath string) error { serve.r = regexp.MustCompile(serve.Path) } + serve.cache = cacheUnset + if serve.Cache != "" { + serve.cache, err = strconv.ParseInt(serve.Cache, 10, 64) + if err != nil { + log.Fatalf("failed to parse cache duration for path %s: %s", serve.Path, err) + } + } + if serve.FastCGI != "" { if serve.Root == "" { log.Fatalf("root must be specified to use fastcgi resource %s of path %s%s", serve.FastCGI, hostname, serve.Path) diff --git a/server.go b/server.go index e132be6..6c87bda 100644 --- a/server.go +++ b/server.go @@ -86,8 +86,8 @@ func writeSuccess(c net.Conn, serve *pathConfig, contentType string, size int64) meta += fmt.Sprintf("; size=%d", size) } - if serve.Cache != -1965 { - meta += fmt.Sprintf("; cache=%d", serve.Cache) + if serve.cache != cacheUnset { + meta += fmt.Sprintf("; cache=%d", serve.cache) } writeHeader(c, statusSuccess, meta)