mirror of
https://code.rocketnine.space/tslocum/twins.git
synced 2024-11-27 09:38:14 +01:00
Fix cache attribute parsing
This commit is contained in:
parent
8d02c6d779
commit
05da75b22b
3 changed files with 26 additions and 15 deletions
20
PROPOSALS.md
20
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
|
||||
```
|
||||
|
|
13
config.go
13
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
|
||||
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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue