1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-12-12 05:20:26 +00:00

Merge pull request #37 from hugmouse/Empty-page-handling

Sending a 404 status if there is no content on the page
This commit is contained in:
Timur Ismagilov 2021-03-05 19:13:59 +05:00 committed by GitHub
commit b9806c89e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 6 deletions

View File

@ -112,10 +112,19 @@ func handlerHypha(w http.ResponseWriter, rq *http.Request) {
contents = views.AttachmentHTML(h) + contents
}
}
util.HTTP200Page(w,
views.BaseHTML(
util.BeautifulName(hyphaName),
views.HyphaHTML(rq, h, contents),
u,
openGraph))
if contents == "" {
util.HTTP404Page(w,
views.BaseHTML(
util.BeautifulName(hyphaName),
views.HyphaHTML(rq, h, contents),
u,
openGraph))
} else {
util.HTTP200Page(w,
views.BaseHTML(
util.BeautifulName(hyphaName),
views.HyphaHTML(rq, h, contents),
u,
openGraph))
}
}

View File

@ -53,6 +53,13 @@ func ShorterPath(path string) string {
return path
}
// HTTP404Page writes a 404 error in the status, needed when no content is found on the page.
func HTTP404Page(w http.ResponseWriter, page string) {
w.Header().Set("Content-Type", "text/html;charset=utf-8")
w.WriteHeader(http.StatusNotFound)
w.Write([]byte(page))
}
// HTTP200Page wraps some frequently used things for successful 200 responses.
func HTTP200Page(w http.ResponseWriter, page string) {
w.Header().Set("Content-Type", "text/html;charset=utf-8")