Add configuration option Lang

This commit is contained in:
Trevor Slocum 2020-12-02 10:29:23 -08:00
parent f91f42464d
commit 19b89bfd9e
3 changed files with 23 additions and 4 deletions

View file

@ -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 When enabled, directories without an index file will serve a list of their
contents. This attribute is disabled by default. contents. This attribute is disabled by default.
##### Lang
Specifies content language. This is sent to clients via the MIME type `lang` parameter.
##### Log ##### Log
Path to log file. Requests are logged in [Apache format](https://httpd.apache.org/docs/2.2/logs.html#combined), 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 default: # Default host configuration
paths: # Default path attributes paths: # Default path attributes
- -
lang: en
log: /srv/log/gemini.log log: /srv/log/gemini.log
symlinks: true # Follow symbolic links symlinks: true # Follow symbolic links
gemini.rocks: gemini.rocks:

View file

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

View file

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