aboutsummaryrefslogtreecommitdiffstats
path: root/modules
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 /modules
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 'modules')
-rw-r--r--modules/context/api.go4
-rw-r--r--modules/context/context.go6
-rw-r--r--modules/context/repo.go2
-rw-r--r--modules/lfs/http_client_test.go2
-rw-r--r--modules/private/restore_repo.go2
-rw-r--r--modules/web/route_test.go2
6 files changed, 9 insertions, 9 deletions
diff --git a/modules/context/api.go b/modules/context/api.go
index c1b31dcff9..e847ca35fa 100644
--- a/modules/context/api.go
+++ b/modules/context/api.go
@@ -214,7 +214,7 @@ func (ctx *APIContext) RequireCSRF() {
if len(headerToken) > 0 || len(formValueToken) > 0 {
Validate(ctx.Context, ctx.csrf)
} else {
- ctx.Context.Error(401, "Missing CSRF token.")
+ ctx.Context.Error(http.StatusUnauthorized, "Missing CSRF token.")
}
}
@@ -239,7 +239,7 @@ func (ctx *APIContext) CheckForOTP() {
return
}
if !ok {
- ctx.Context.Error(401)
+ ctx.Context.Error(http.StatusUnauthorized)
return
}
}
diff --git a/modules/context/context.go b/modules/context/context.go
index 57448907e2..61f58eabb2 100644
--- a/modules/context/context.go
+++ b/modules/context/context.go
@@ -139,7 +139,7 @@ func RedirectToUser(ctx *Context, userName string, redirectUserID int64) {
if ctx.Req.URL.RawQuery != "" {
redirectPath += "?" + ctx.Req.URL.RawQuery
}
- ctx.Redirect(path.Join(setting.AppSubURL, redirectPath))
+ ctx.Redirect(path.Join(setting.AppSubURL, redirectPath), http.StatusTemporaryRedirect)
}
// HasAPIError returns true if error occurs in form validation.
@@ -215,7 +215,7 @@ func (ctx *Context) HTML(status int, name base.TplName) {
// RenderToString renders the template content to a string
func (ctx *Context) RenderToString(name base.TplName, data map[string]interface{}) (string, error) {
var buf strings.Builder
- err := ctx.Render.HTML(&buf, 200, string(name), data)
+ err := ctx.Render.HTML(&buf, http.StatusOK, string(name), data)
return buf.String(), err
}
@@ -397,7 +397,7 @@ func (ctx *Context) JSON(status int, content interface{}) {
// Redirect redirects the request
func (ctx *Context) Redirect(location string, status ...int) {
- code := http.StatusFound
+ code := http.StatusSeeOther
if len(status) == 1 {
code = status[0]
}
diff --git a/modules/context/repo.go b/modules/context/repo.go
index f8b07ffb05..87be2af135 100644
--- a/modules/context/repo.go
+++ b/modules/context/repo.go
@@ -335,7 +335,7 @@ func RedirectToRepo(ctx *Context, redirectRepoID int64) {
if ctx.Req.URL.RawQuery != "" {
redirectPath += "?" + ctx.Req.URL.RawQuery
}
- ctx.Redirect(path.Join(setting.AppSubURL, redirectPath))
+ ctx.Redirect(path.Join(setting.AppSubURL, redirectPath), http.StatusTemporaryRedirect)
}
func repoAssignment(ctx *Context, repo *repo_model.Repository) {
diff --git a/modules/lfs/http_client_test.go b/modules/lfs/http_client_test.go
index 0ffe663da5..8f6dcb1966 100644
--- a/modules/lfs/http_client_test.go
+++ b/modules/lfs/http_client_test.go
@@ -81,7 +81,7 @@ func lfsTestRoundtripHandler(req *http.Request) *http.Response {
Objects: []*ObjectResponse{
{
Error: &ObjectError{
- Code: 404,
+ Code: http.StatusNotFound,
Message: "Object not found",
},
},
diff --git a/modules/private/restore_repo.go b/modules/private/restore_repo.go
index 347ed5e78a..b1561f392b 100644
--- a/modules/private/restore_repo.go
+++ b/modules/private/restore_repo.go
@@ -45,7 +45,7 @@ func RestoreRepo(ctx context.Context, repoDir, ownerName, repoName string, units
}
defer resp.Body.Close()
- if resp.StatusCode != 200 {
+ if resp.StatusCode != http.StatusOK {
ret := struct {
Err string `json:"err"`
}{}
diff --git a/modules/web/route_test.go b/modules/web/route_test.go
index a8470fec94..801afe92c9 100644
--- a/modules/web/route_test.go
+++ b/modules/web/route_test.go
@@ -67,7 +67,7 @@ func TestRoute2(t *testing.T) {
route = 1
})
}, func(resp http.ResponseWriter, req *http.Request) {
- resp.WriteHeader(200)
+ resp.WriteHeader(http.StatusOK)
})
r.Group("/issues/{index}", func() {