diff --git a/core/response/write.go b/core/response/write.go index 7656b33d..cb1fa0bd 100644 --- a/core/response/write.go +++ b/core/response/write.go @@ -48,8 +48,8 @@ func WriteServerError(w http.ResponseWriter, method string, err error) { // WriteError notifies HTTP client of general application error. func WriteError(w http.ResponseWriter, method string) { - writeStatus(w, http.StatusBadRequest) - w.Write([]byte("{Error: 'Internal server error'}")) + writeStatus(w, http.StatusBadRequest) + w.Write([]byte("{Error: 'Internal server error'}")) } // WriteDuplicateError notifies HTTP client of duplicate data that has been rejected. @@ -114,3 +114,17 @@ func WriteJSON(w http.ResponseWriter, v interface{}) { j, _ := json.Marshal(v) w.Write(j) } + +// WriteText to HTTP response +func WriteText(w http.ResponseWriter, data []byte) { + w.Header().Set("Content-Type", "text/plain; charset=utf-8") + w.WriteHeader(http.StatusOK) + w.Write(data) +} + +// WriteXML to HTTP response +func WriteXML(w http.ResponseWriter, data []byte) { + w.Header().Set("Content-Type", "application/xml; charset=utf-8") + w.WriteHeader(http.StatusOK) + w.Write(data) +} diff --git a/domain/meta/endpoint.go b/domain/meta/endpoint.go index 8ddf0997..2a17dea4 100644 --- a/domain/meta/endpoint.go +++ b/domain/meta/endpoint.go @@ -138,7 +138,7 @@ Disallow: /attachment/* Sitemap: %s`, sitemap) } - response.WriteBytes(w, []byte(robots)) + response.WriteText(w, []byte(robots)) } // Sitemap returns URLs that can be indexed. @@ -205,7 +205,7 @@ func (h *Handler) Sitemap(w http.ResponseWriter, r *http.Request) { t := template.Must(template.New("tmp").Parse(sitemap)) t.Execute(buffer, &items) - response.WriteBytes(w, buffer.Bytes()) + response.WriteXML(w, buffer.Bytes()) } type sitemapItem struct {