1
0
Fork 0

Add DefaultEncoding option to config/.molly files. Closes #19.

This commit is contained in:
Solderpunk 2023-01-29 12:07:52 +01:00
parent f05bab2b73
commit a41898b012
3 changed files with 13 additions and 1 deletions

View file

@ -229,6 +229,8 @@ examples of the appropriate syntax.
will be used instead of one inferred from the filename extension.
* `DefaultLang`: If this option is set, it will be served as the
`lang` parameter of the MIME type for all `text/gemini` content.
* `DefaultEncoding`: If this option is set, it will be served as the
`charset` parameter of the MIME type for all `text/gemini` content.
### Directory listings
@ -369,6 +371,7 @@ other settings in `.molly` files will be ignored:
* `CertificateZones`
* `DefaultLang`
* `DefaultEncoding`
* `DirectorySort`
* `DirectoryReverse`
* `DirectoryTitles`

View file

@ -18,6 +18,7 @@ type Config struct {
HomeDocBase string
GeminiExt string
DefaultLang string
DefaultEncoding string
AccessLog string
ErrorLog string
ReadMollyFiles bool
@ -39,6 +40,7 @@ type MollyFile struct {
MimeOverrides map[string]string
CertificateZones map[string][]string
DefaultLang string
DefaultEncoding string
DirectorySort string
DirectoryReverse bool
DirectoryTitles bool
@ -57,6 +59,7 @@ func getConfig(filename string) (Config, error) {
config.HomeDocBase = "users"
config.GeminiExt = "gmi"
config.DefaultLang = ""
config.DefaultEncoding = ""
config.AccessLog = "access.log"
config.ErrorLog = "error.log"
config.TempRedirects = make(map[string]string)
@ -139,6 +142,7 @@ func parseMollyFiles(path string, config *Config, errorLog *log.Logger) {
var mollyFile MollyFile
mollyFile.GeminiExt = config.GeminiExt
mollyFile.DefaultLang = config.DefaultLang
mollyFile.DefaultEncoding = config.DefaultEncoding
mollyFile.DirectorySort = config.DirectorySort
mollyFile.DirectoryReverse = config.DirectoryReverse
mollyFile.DirectoryTitles = config.DirectoryTitles
@ -176,6 +180,7 @@ func parseMollyFiles(path string, config *Config, errorLog *log.Logger) {
// Overwrite main Config using MollyFile
config.GeminiExt = mollyFile.GeminiExt
config.DefaultLang = mollyFile.DefaultLang
config.DefaultEncoding = mollyFile.DefaultEncoding
config.DirectorySort = mollyFile.DirectorySort
config.DirectoryReverse = mollyFile.DirectoryReverse
config.DirectoryTitles = mollyFile.DirectoryTitles

View file

@ -254,8 +254,12 @@ func serveFile(path string, log *LogEntry, conn net.Conn, config Config, errorLo
if mimeType == "" {
mimeType = "application/octet-stream"
}
// Add charset parameter
if strings.HasPrefix(mimeType,"text/gemini") && config.DefaultEncoding != "" {
mimeType += "; charset=" + config.DefaultEncoding
}
// Add lang parameter
if mimeType == "text/gemini" && config.DefaultLang != "" {
if strings.HasPrefix(mimeType,"text/gemini") && config.DefaultLang != "" {
mimeType += "; lang=" + config.DefaultLang
}