website: serve non-HTML files as raw bytes

The website has several non-HTML files that mostly serve as examples
(eg: https://camlistore.org/doc/json-signing/example/signing-before.camli).
Today these files are parsed and rendered the same as HTML files, which
is particularly bad for these json-signing examples.  Instead, they
should be served raw, without any interpretation.

Change-Id: I09f7de130e55da7b2e585f1a110bbbf391f2279f
This commit is contained in:
Will Norris 2016-04-26 16:25:45 -07:00
parent 066db0952c
commit 3cc1efc75e
5 changed files with 5 additions and 0 deletions

View File

@ -369,6 +369,11 @@ var markdownRenderer = blackfriday.HtmlRenderer(markdownHTMLFlags, "", "")
// serveFile serves a file from disk, converting any markdown to HTML.
func serveFile(rw http.ResponseWriter, req *http.Request, relPath, absPath string) {
if !strings.HasSuffix(absPath, ".html") && !strings.HasSuffix(absPath, ".md") {
http.ServeFile(rw, req, absPath)
return
}
data, err := ioutil.ReadFile(absPath)
if err != nil {
serveError(rw, req, absPath, err)