forked from tslocum/twins
1
0
Fork 0

Fix sending custom content types to HTTP clients

Resolves #14.
This commit is contained in:
Trevor Slocum 2021-07-22 19:49:24 -07:00
parent 12aa024671
commit 0c4c7e8ecb
2 changed files with 8 additions and 3 deletions

View File

@ -234,6 +234,7 @@ listen: :1965
# Custom content types
types:
.json: application/json; charset=UTF-8
.js: application/javascript; charset=UTF-8
# Hosts and paths to serve
hosts:

View File

@ -183,11 +183,15 @@ func serveHTTPS(w http.ResponseWriter, r *http.Request) (int, int64, string) {
fileExt := strings.ToLower(filepath.Ext(filePath))
if fileExt == ".gmi" || fileExt == ".gemini" {
result = gmitohtml.Convert([]byte(data), r.URL.String())
} else if fileExt == ".htm" || fileExt == ".html" {
result = data
} else {
result = data
contentType = plainType
if fileExt == ".htm" || fileExt == ".html" {
// HTML content type already set
} else if customType := config.Types[filepath.Ext(filePath)]; customType != "" {
contentType = customType
} else {
contentType = plainType
}
}
status := http.StatusOK