speculator: Sent Content-Type: text/html header

Go is auto-detecting that this is XML (because for some reason we
generate XHTML), and serving it with a Content-Type header text/xml.

This causes the browser to render it as XHTML, which gives interesting
quirks like extra newlines.

This forces the browser to interpret it as HTML.

What we should probably do instead of stop generating XHTML and start
generating HTML. But in the mean time, this will fix the rendering
issues.
pull/977/head
Daniel Wagner-Hall 9 years ago
parent 161441fa3a
commit 559747e77a

@ -384,9 +384,9 @@ func main() {
log.Fatal(err) log.Fatal(err)
} }
s := server{masterCloneDir} s := server{masterCloneDir}
http.HandleFunc("/spec/", s.serveSpec) http.HandleFunc("/spec/", forceHTML(s.serveSpec))
http.HandleFunc("/diff/rst/", s.serveRSTDiff) http.HandleFunc("/diff/rst/", forceHTML(s.serveRSTDiff))
http.HandleFunc("/diff/html/", s.serveHTMLDiff) http.HandleFunc("/diff/html/", forceHTML(s.serveHTMLDiff))
http.HandleFunc("/healthz", serveText("ok")) http.HandleFunc("/healthz", serveText("ok"))
http.HandleFunc("/", listPulls) http.HandleFunc("/", listPulls)
@ -394,6 +394,13 @@ func main() {
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", *port), nil)) log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", *port), nil))
} }
func forceHTML(h func(w http.ResponseWriter, req *http.Request)) func(w http.ResponseWriter, req *http.Request) {
return func(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Type", "text/html")
h(w, req)
}
}
func serveText(s string) func(http.ResponseWriter, *http.Request) { func serveText(s string) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, req *http.Request) { return func(w http.ResponseWriter, req *http.Request) {
io.WriteString(w, s) io.WriteString(w, s)

Loading…
Cancel
Save