Browse Source

Add configuration option Lang

master
Trevor Slocum 2 years ago
parent
commit
19b89bfd9e
  1. 5
      CONFIGURATION.md
  2. 6
      config.go
  3. 16
      server.go

5
CONFIGURATION.md

@ -133,6 +133,10 @@ Request sensitive text input from the user. Text will not be shown as it is ente
When enabled, directories without an index file will serve a list of their
contents. This attribute is disabled by default.
##### Lang
Specifies content language. This is sent to clients via the MIME type `lang` parameter.
##### Log
Path to log file. Requests are logged in [Apache format](https://httpd.apache.org/docs/2.2/logs.html#combined),
@ -199,6 +203,7 @@ hosts:
default: # Default host configuration
paths: # Default path attributes
-
lang: en
log: /srv/log/gemini.log
symlinks: true # Follow symbolic links
gemini.rocks:

6
config.go

@ -50,6 +50,9 @@ type pathConfig struct {
// FastCGI server address
FastCGI string
// Language
Lang string
// Log file
Log string
@ -188,6 +191,9 @@ func readconfig(configPath string) error {
if defaultPath.FastCGI != "" && serve.FastCGI == "" {
serve.FastCGI = defaultPath.FastCGI
}
if defaultPath.Lang != "" && serve.Lang == "" {
serve.Lang = defaultPath.Lang
}
if defaultPath.Log != "" && serve.Log == "" {
serve.Log = defaultPath.Log
}

16
server.go

@ -82,19 +82,27 @@ func writeStatus(c net.Conn, code int) int {
}
func writeSuccess(c net.Conn, serve *pathConfig, contentType string, size int64) int {
// Content type
meta := contentType
if serve.Type != "" {
meta = serve.Type
}
if !config.DisableSize && size >= 0 {
meta += fmt.Sprintf("; size=%d", size)
}
// Cache
if serve.cache != cacheUnset {
meta += fmt.Sprintf("; cache=%d", serve.cache)
}
// Language
if serve.Lang != "" {
meta += fmt.Sprintf("; lang=%s", serve.Lang)
}
// Size
if !config.DisableSize && size >= 0 {
meta += fmt.Sprintf("; size=%d", size)
}
writeHeader(c, statusSuccess, meta)
return statusSuccess
}

Loading…
Cancel
Save