summaryrefslogtreecommitdiffstats
path: root/routers/web/base.go
diff options
context:
space:
mode:
authorKN4CK3R <admin@oldschoolhack.me>2022-03-23 05:54:07 +0100
committerGitHub <noreply@github.com>2022-03-23 12:54:07 +0800
commit3f280f89e7471a6dcdaefccc64a8d39188970e63 (patch)
treeff09b6dcb00b4c0ff0c436c4523d89a5c13f3a94 /routers/web/base.go
parent395117d3014124b9147a1aabf76ee175e720b275 (diff)
downloadgitea-3f280f89e7471a6dcdaefccc64a8d39188970e63.tar.gz
gitea-3f280f89e7471a6dcdaefccc64a8d39188970e63.zip
Update HTTP status codes to modern codes (#18063)
* 2xx/3xx/4xx/5xx -> http.Status... * http.StatusFound -> http.StatusTemporaryRedirect * http.StatusMovedPermanently -> http.StatusPermanentRedirect
Diffstat (limited to 'routers/web/base.go')
-rw-r--r--routers/web/base.go16
1 files changed, 8 insertions, 8 deletions
diff --git a/routers/web/base.go b/routers/web/base.go
index 3e873c5826..938abaef81 100644
--- a/routers/web/base.go
+++ b/routers/web/base.go
@@ -50,11 +50,11 @@ func storageHandler(storageSetting setting.Storage, prefix string, objStore stor
if err != nil {
if os.IsNotExist(err) || errors.Is(err, os.ErrNotExist) {
log.Warn("Unable to find %s %s", prefix, rPath)
- http.Error(w, "file not found", 404)
+ http.Error(w, "file not found", http.StatusNotFound)
return
}
log.Error("Error whilst getting URL for %s %s. Error: %v", prefix, rPath, err)
- http.Error(w, fmt.Sprintf("Error whilst getting URL for %s %s", prefix, rPath), 500)
+ http.Error(w, fmt.Sprintf("Error whilst getting URL for %s %s", prefix, rPath), http.StatusInternalServerError)
return
}
@@ -62,7 +62,7 @@ func storageHandler(storageSetting setting.Storage, prefix string, objStore stor
w,
req,
u.String(),
- http.StatusMovedPermanently,
+ http.StatusPermanentRedirect,
)
})
}
@@ -82,7 +82,7 @@ func storageHandler(storageSetting setting.Storage, prefix string, objStore stor
rPath := strings.TrimPrefix(req.URL.Path, "/"+prefix+"/")
rPath = path.Clean("/" + strings.ReplaceAll(rPath, "\\", "/"))[1:]
if rPath == "" {
- http.Error(w, "file not found", 404)
+ http.Error(w, "file not found", http.StatusNotFound)
return
}
@@ -96,11 +96,11 @@ func storageHandler(storageSetting setting.Storage, prefix string, objStore stor
if err != nil {
if os.IsNotExist(err) || errors.Is(err, os.ErrNotExist) {
log.Warn("Unable to find %s %s", prefix, rPath)
- http.Error(w, "file not found", 404)
+ http.Error(w, "file not found", http.StatusNotFound)
return
}
log.Error("Error whilst opening %s %s. Error: %v", prefix, rPath, err)
- http.Error(w, fmt.Sprintf("Error whilst opening %s %s", prefix, rPath), 500)
+ http.Error(w, fmt.Sprintf("Error whilst opening %s %s", prefix, rPath), http.StatusInternalServerError)
return
}
defer fr.Close()
@@ -108,7 +108,7 @@ func storageHandler(storageSetting setting.Storage, prefix string, objStore stor
_, err = io.Copy(w, fr)
if err != nil {
log.Error("Error whilst rendering %s %s. Error: %v", prefix, rPath, err)
- http.Error(w, fmt.Sprintf("Error whilst rendering %s %s", prefix, rPath), 500)
+ http.Error(w, fmt.Sprintf("Error whilst rendering %s %s", prefix, rPath), http.StatusInternalServerError)
return
}
})
@@ -163,7 +163,7 @@ func Recovery() func(next http.Handler) http.Handler {
if !setting.IsProd {
store["ErrorMsg"] = combinedErr
}
- err = rnd.HTML(w, 500, "status/500", templates.BaseVars().Merge(store))
+ err = rnd.HTML(w, http.StatusInternalServerError, "status/500", templates.BaseVars().Merge(store))
if err != nil {
log.Error("%v", err)
}