response simple text message for not html request when 404 (#15229)

* response simple text message for not html request when response 404

Signed-off-by: a1012112796 <1012112796@qq.com>
tokarchuk/v1.17
a1012112796 4 years ago committed by GitHub
parent 9b316a327e
commit 43fb4921e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 17
      modules/context/context.go

@ -229,6 +229,23 @@ func (ctx *Context) notFoundInternal(title string, err error) {
}
}
// response simple meesage if Accept isn't text/html
reqTypes, has := ctx.Req.Header["Accept"]
if has && len(reqTypes) > 0 {
notHTML := true
for _, part := range reqTypes {
if strings.Contains(part, "text/html") {
notHTML = false
break
}
}
if notHTML {
ctx.PlainText(404, []byte("Not found.\n"))
return
}
}
ctx.Data["IsRepo"] = ctx.Repo.Repository != nil
ctx.Data["Title"] = "Page Not Found"
ctx.HTML(http.StatusNotFound, base.TplName("status/404"))

Loading…
Cancel
Save