From a7f19759dfd5c90697a5000f8ae933a0ab22bd95 Mon Sep 17 00:00:00 2001 From: Peter Stuifzand Date: Sat, 15 Sep 2018 10:51:27 +0200 Subject: [PATCH] Add utf-8 to content-type --- cmd/eksterd/microsub.go | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/cmd/eksterd/microsub.go b/cmd/eksterd/microsub.go index 689cde3..71e49e3 100644 --- a/cmd/eksterd/microsub.go +++ b/cmd/eksterd/microsub.go @@ -69,6 +69,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } } + const OutputContentType = "application/json; charset=utf-8" if r.Method == http.MethodGet { w.Header().Add("Access-Control-Allow-Origin", "*") values := r.URL.Query() @@ -80,7 +81,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } jw := json.NewEncoder(w) - w.Header().Add("Content-Type", "application/json") + w.Header().Add("Content-Type", OutputContentType) err = jw.Encode(map[string][]microsub.Channel{ "channels": channels, }) @@ -95,7 +96,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } jw := json.NewEncoder(w) - w.Header().Add("Content-Type", "application/json") + w.Header().Add("Content-Type", OutputContentType) jw.SetIndent("", " ") jw.SetEscapeHTML(false) err = jw.Encode(timeline) @@ -111,7 +112,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } jw := json.NewEncoder(w) jw.SetIndent("", " ") - w.Header().Add("Content-Type", "application/json") + w.Header().Add("Content-Type", OutputContentType) err = jw.Encode(timeline) if err != nil { http.Error(w, err.Error(), 500) @@ -125,7 +126,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } jw := json.NewEncoder(w) - w.Header().Add("Content-Type", "application/json") + w.Header().Add("Content-Type", OutputContentType) err = jw.Encode(map[string][]microsub.Feed{ "items": following, }) @@ -157,7 +158,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { http.Error(w, err.Error(), 500) return } - w.Header().Add("Content-Type", "application/json") + w.Header().Add("Content-Type", OutputContentType) fmt.Fprintln(w, "[]") h.Backend.(Debug).Debug() return @@ -170,7 +171,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { http.Error(w, err.Error(), 500) return } - w.Header().Add("Content-Type", "application/json") + w.Header().Add("Content-Type", OutputContentType) err = jw.Encode(channel) if err != nil { http.Error(w, err.Error(), 500) @@ -182,7 +183,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { http.Error(w, err.Error(), 500) return } - w.Header().Add("Content-Type", "application/json") + w.Header().Add("Content-Type", OutputContentType) err = jw.Encode(channel) if err != nil { http.Error(w, err.Error(), 500) @@ -199,7 +200,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { http.Error(w, err.Error(), 500) return } - w.Header().Add("Content-Type", "application/json") + w.Header().Add("Content-Type", OutputContentType) jw := json.NewEncoder(w) err = jw.Encode(feed) if err != nil { @@ -214,7 +215,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { http.Error(w, err.Error(), 500) return } - w.Header().Add("Content-Type", "application/json") + w.Header().Add("Content-Type", OutputContentType) fmt.Fprintln(w, "[]") } else if action == "search" { query := values.Get("query") @@ -224,7 +225,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } jw := json.NewEncoder(w) - w.Header().Add("Content-Type", "application/json") + w.Header().Add("Content-Type", OutputContentType) err = jw.Encode(map[string][]microsub.Feed{ "results": feeds, }) @@ -264,7 +265,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { http.Error(w, fmt.Sprintf("unknown method in timeline %s\n", method), 500) return } - w.Header().Add("Content-Type", "application/json") + w.Header().Add("Content-Type", OutputContentType) fmt.Fprintln(w, "[]") } else { http.Error(w, fmt.Sprintf("unknown action %s\n", action), 500)