From 0c4c7e8ecb462671818220103f9028498129f804 Mon Sep 17 00:00:00 2001 From: Trevor Slocum Date: Thu, 22 Jul 2021 19:49:24 -0700 Subject: [PATCH] Fix sending custom content types to HTTP clients Resolves #14. --- CONFIGURATION.md | 1 + serve_https.go | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CONFIGURATION.md b/CONFIGURATION.md index 0470cab..dee59a4 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -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: diff --git a/serve_https.go b/serve_https.go index e75e6aa..0f28ba2 100644 --- a/serve_https.go +++ b/serve_https.go @@ -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