1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-18 20:59:43 +02:00

Fix regression for robots.txt and sitemap.xml

This commit is contained in:
Harvey Kandola 2022-10-21 11:13:03 -04:00
parent e0e3f0c141
commit 6993dc678f
2 changed files with 18 additions and 4 deletions

View file

@ -48,8 +48,8 @@ func WriteServerError(w http.ResponseWriter, method string, err error) {
// WriteError notifies HTTP client of general application error. // WriteError notifies HTTP client of general application error.
func WriteError(w http.ResponseWriter, method string) { func WriteError(w http.ResponseWriter, method string) {
writeStatus(w, http.StatusBadRequest) writeStatus(w, http.StatusBadRequest)
w.Write([]byte("{Error: 'Internal server error'}")) w.Write([]byte("{Error: 'Internal server error'}"))
} }
// WriteDuplicateError notifies HTTP client of duplicate data that has been rejected. // 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) j, _ := json.Marshal(v)
w.Write(j) 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)
}

View file

@ -138,7 +138,7 @@ Disallow: /attachment/*
Sitemap: %s`, sitemap) Sitemap: %s`, sitemap)
} }
response.WriteBytes(w, []byte(robots)) response.WriteText(w, []byte(robots))
} }
// Sitemap returns URLs that can be indexed. // 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 := template.Must(template.New("tmp").Parse(sitemap))
t.Execute(buffer, &items) t.Execute(buffer, &items)
response.WriteBytes(w, buffer.Bytes()) response.WriteXML(w, buffer.Bytes())
} }
type sitemapItem struct { type sitemapItem struct {