From 1d445cb61b4716eb7bba5e50d0b5f9ed3cc84822 Mon Sep 17 00:00:00 2001 From: Arzumify Date: Mon, 14 Oct 2024 13:10:51 +0100 Subject: [PATCH] Made renderX provide content types to not make forgejo complain Signed-off-by: Arzumify --- services-src/auth/main.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/services-src/auth/main.go b/services-src/auth/main.go index 1a98aa1..cf9e0b5 100644 --- a/services-src/auth/main.go +++ b/services-src/auth/main.go @@ -103,6 +103,13 @@ func renderTemplate(statusCode int, w http.ResponseWriter, data map[string]inter renderString(500, w, "Sorry, something went wrong on our end. Error code: 01. Please report to the administrator.", information) } else { w.WriteHeader(statusCode) + if strings.HasSuffix(templatePath, ".html") { + w.Header().Set("Content-Type", "text/html") + } else if strings.HasSuffix(templatePath, ".json") { + w.Header().Set("Content-Type", "application/json") + } else { + w.Header().Set("Content-Type", "text/plain") + } err = requestedTemplate.Execute(w, data) if err != nil { logFunc(err.Error(), 2, information) @@ -112,6 +119,7 @@ func renderTemplate(statusCode int, w http.ResponseWriter, data map[string]inter } func renderString(statusCode int, w http.ResponseWriter, data string, information library.ServiceInitializationInformation) { + w.Header().Set("Content-Type", "text/plain") w.WriteHeader(statusCode) _, err := w.Write([]byte(data)) if err != nil { @@ -120,6 +128,7 @@ func renderString(statusCode int, w http.ResponseWriter, data string, informatio } func renderJSON(statusCode int, w http.ResponseWriter, data map[string]interface{}, information library.ServiceInitializationInformation) { + w.Header().Set("Content-Type", "application/json") w.WriteHeader(statusCode) err := json.NewEncoder(w).Encode(data) if err != nil {