diff options
author | a1012112796 <1012112796@qq.com> | 2021-04-01 23:11:42 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-01 17:11:42 +0200 |
commit | 43fb4921e3fb67be9f2f3a6d631a21a3322f492b (patch) | |
tree | 487f8dabeb93e351e441415eb9bca832fd9dc93b /modules | |
parent | 9b316a327e900bcef969795e0e563051cc8c4f1b (diff) | |
download | gitea-43fb4921e3fb67be9f2f3a6d631a21a3322f492b.tar.gz gitea-43fb4921e3fb67be9f2f3a6d631a21a3322f492b.zip |
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>
Diffstat (limited to 'modules')
-rw-r--r-- | modules/context/context.go | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/modules/context/context.go b/modules/context/context.go index eecc81406d..a784032606 100644 --- a/modules/context/context.go +++ b/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")) |