From fedb49fef42d994426e5fe1eb35961e7ac02b213 Mon Sep 17 00:00:00 2001 From: Umar Getagazov Date: Wed, 29 Sep 2021 22:02:30 +0700 Subject: [PATCH] Enforce UTF-8 and set correct MIME types for feeds --- web/history.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/web/history.go b/web/history.go index 681a1f6..d6ae80e 100644 --- a/web/history.go +++ b/web/history.go @@ -61,26 +61,26 @@ func handlerRecentChanges(w http.ResponseWriter, rq *http.Request) { } // genericHandlerOfFeeds is a helper function for the web feed handlers. -func genericHandlerOfFeeds(w http.ResponseWriter, rq *http.Request, f func() (string, error), name string) { +func genericHandlerOfFeeds(w http.ResponseWriter, rq *http.Request, f func() (string, error), name string, contentType string) { if content, err := f(); err != nil { w.Header().Set("Content-Type", "text/plain;charset=utf-8") w.WriteHeader(http.StatusInternalServerError) fmt.Fprint(w, "An error while generating "+name+": "+err.Error()) } else { - w.Header().Set("Content-Type", "application/rss+xml") + w.Header().Set("Content-Type", fmt.Sprintf("%s;charset=utf-8", contentType)) w.WriteHeader(http.StatusOK) fmt.Fprint(w, content) } } func handlerRecentChangesRSS(w http.ResponseWriter, rq *http.Request) { - genericHandlerOfFeeds(w, rq, history.RecentChangesRSS, "RSS") + genericHandlerOfFeeds(w, rq, history.RecentChangesRSS, "RSS", "application/rss+xml") } func handlerRecentChangesAtom(w http.ResponseWriter, rq *http.Request) { - genericHandlerOfFeeds(w, rq, history.RecentChangesAtom, "Atom") + genericHandlerOfFeeds(w, rq, history.RecentChangesAtom, "Atom", "application/atom+xml") } func handlerRecentChangesJSON(w http.ResponseWriter, rq *http.Request) { - genericHandlerOfFeeds(w, rq, history.RecentChangesJSON, "JSON feed") + genericHandlerOfFeeds(w, rq, history.RecentChangesJSON, "JSON feed", "application/json") }