From 7b034f10af4bd5f0712aca8a31c728ca947b6f46 Mon Sep 17 00:00:00 2001 From: thinkpadmaster Date: Mon, 28 Aug 2023 09:47:47 -0500 Subject: Set Content-Type in header --- handle.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'handle.go') diff --git a/handle.go b/handle.go index 5b84d4e..54ee085 100644 --- a/handle.go +++ b/handle.go @@ -6,6 +6,8 @@ import ( ) func (app *application) home(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "text/html; charset=utf-8") + path := strings.Split(r.URL.Path, "/") if path[1] != "" { app.notFound(w) @@ -26,6 +28,8 @@ func (app *application) home(w http.ResponseWriter, r *http.Request) { } func (app *application) about(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "text/html; charset=utf-8") + path := strings.Split(r.URL.Path, "/") pathLen := len(path) @@ -44,6 +48,8 @@ func (app *application) about(w http.ResponseWriter, r *http.Request) { } func (app *application) aggregate(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "text/html; charset=utf-8") + p, err := app.loadPosts("html"+strings.TrimSuffix(r.URL.Path, "/"), -1) if err != nil { app.notFound(w) @@ -53,10 +59,12 @@ func (app *application) aggregate(w http.ResponseWriter, r *http.Request) { } func (app *application) post(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "text/html; charset=utf-8") + path := strings.Split(r.URL.Path, "/") if len(path) > 4 { app.notFound(w) - } else if r.URL.Path == "/blog" || r.URL.Path == "/projects" { + } else if r.URL.Path == "/blog" || r.URL.Path == "/projects" { // Make a more encompasing change here app.aggregate(w, r) } else if path[2] == "" { http.Redirect(w, r, "/"+path[1], http.StatusFound) -- cgit v1.2.3