diff options
author | KN4CK3R <admin@oldschoolhack.me> | 2022-03-23 05:54:07 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-23 12:54:07 +0800 |
commit | 3f280f89e7471a6dcdaefccc64a8d39188970e63 (patch) | |
tree | ff09b6dcb00b4c0ff0c436c4523d89a5c13f3a94 /routers | |
parent | 395117d3014124b9147a1aabf76ee175e720b275 (diff) | |
download | gitea-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')
27 files changed, 81 insertions, 83 deletions
diff --git a/routers/api/v1/org/member.go b/routers/api/v1/org/member.go index 7f82f19385..9dae15462f 100644 --- a/routers/api/v1/org/member.go +++ b/routers/api/v1/org/member.go @@ -130,7 +130,7 @@ func IsMember(ctx *context.APIContext) { // responses: // "204": // description: user is a member - // "302": + // "303": // description: redirection to /orgs/{org}/public_members/{username} // "404": // description: user is not a member @@ -161,7 +161,7 @@ func IsMember(ctx *context.APIContext) { } redirectURL := setting.AppSubURL + "/api/v1/orgs/" + url.PathEscape(ctx.Org.Organization.Name) + "/public_members/" + url.PathEscape(userToCheck.Name) - ctx.Redirect(redirectURL, 302) + ctx.Redirect(redirectURL) } // IsPublicMember check if a user is a public member of an organization diff --git a/routers/api/v1/repo/issue_tracked_time.go b/routers/api/v1/repo/issue_tracked_time.go index 5cc39becb8..19732c101f 100644 --- a/routers/api/v1/repo/issue_tracked_time.go +++ b/routers/api/v1/repo/issue_tracked_time.go @@ -288,7 +288,7 @@ func ResetIssueTime(ctx *context.APIContext) { } return } - ctx.Status(204) + ctx.Status(http.StatusNoContent) } // DeleteTime delete a specific time by id diff --git a/routers/common/middleware.go b/routers/common/middleware.go index 880700969a..591c4cf30e 100644 --- a/routers/common/middleware.go +++ b/routers/common/middleware.go @@ -70,9 +70,9 @@ func Middlewares() []func(http.Handler) http.Handler { combinedErr := fmt.Sprintf("PANIC: %v\n%s", err, log.Stack(2)) log.Error("%v", combinedErr) if setting.IsProd { - http.Error(resp, http.StatusText(500), 500) + http.Error(resp, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) } else { - http.Error(resp, combinedErr, 500) + http.Error(resp, combinedErr, http.StatusInternalServerError) } } }() diff --git a/routers/install/install.go b/routers/install/install.go index 98eeb5f8a0..164ce68405 100644 --- a/routers/install/install.go +++ b/routers/install/install.go @@ -59,7 +59,7 @@ func Init(next http.Handler) http.Handler { return http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) { if setting.InstallLock { resp.Header().Add("Refresh", "1; url="+setting.AppURL+"user/login") - _ = rnd.HTML(resp, 200, string(tplPostInstall), nil) + _ = rnd.HTML(resp, http.StatusOK, string(tplPostInstall), nil) return } locale := middleware.Locale(resp, req) diff --git a/routers/install/routes.go b/routers/install/routes.go index f377cd40c9..ef96e99628 100644 --- a/routers/install/routes.go +++ b/routers/install/routes.go @@ -41,9 +41,9 @@ func installRecovery() func(next http.Handler) http.Handler { combinedErr := fmt.Sprintf("PANIC: %v\n%s", err, log.Stack(2)) log.Error("%s", combinedErr) if setting.IsProd { - http.Error(w, http.StatusText(500), 500) + http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) } else { - http.Error(w, combinedErr, 500) + http.Error(w, combinedErr, http.StatusInternalServerError) } } }() @@ -66,7 +66,7 @@ func installRecovery() 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) } diff --git a/routers/web/admin/admin.go b/routers/web/admin/admin.go index 63bc7de7d7..4c700df354 100644 --- a/routers/web/admin/admin.go +++ b/routers/web/admin/admin.go @@ -346,7 +346,7 @@ func Queue(ctx *context.Context) { qid := ctx.ParamsInt64("qid") mq := queue.GetManager().GetManagedQueue(qid) if mq == nil { - ctx.Status(404) + ctx.Status(http.StatusNotFound) return } ctx.Data["Title"] = ctx.Tr("admin.monitor.queue", mq.Name) @@ -361,7 +361,7 @@ func WorkerCancel(ctx *context.Context) { qid := ctx.ParamsInt64("qid") mq := queue.GetManager().GetManagedQueue(qid) if mq == nil { - ctx.Status(404) + ctx.Status(http.StatusNotFound) return } pid := ctx.ParamsInt64("pid") @@ -377,7 +377,7 @@ func Flush(ctx *context.Context) { qid := ctx.ParamsInt64("qid") mq := queue.GetManager().GetManagedQueue(qid) if mq == nil { - ctx.Status(404) + ctx.Status(http.StatusNotFound) return } timeout, err := time.ParseDuration(ctx.FormString("timeout")) @@ -423,7 +423,7 @@ func AddWorkers(ctx *context.Context) { qid := ctx.ParamsInt64("qid") mq := queue.GetManager().GetManagedQueue(qid) if mq == nil { - ctx.Status(404) + ctx.Status(http.StatusNotFound) return } number := ctx.FormInt("number") @@ -453,7 +453,7 @@ func SetQueueSettings(ctx *context.Context) { qid := ctx.ParamsInt64("qid") mq := queue.GetManager().GetManagedQueue(qid) if mq == nil { - ctx.Status(404) + ctx.Status(http.StatusNotFound) return } if _, ok := mq.Managed.(queue.ManagedPool); !ok { diff --git a/routers/web/admin/notice.go b/routers/web/admin/notice.go index 147e03ba03..b50549b804 100644 --- a/routers/web/admin/notice.go +++ b/routers/web/admin/notice.go @@ -59,10 +59,10 @@ func DeleteNotices(ctx *context.Context) { if err := admin_model.DeleteNoticesByIDs(ids); err != nil { ctx.Flash.Error("DeleteNoticesByIDs: " + err.Error()) - ctx.Status(500) + ctx.Status(http.StatusInternalServerError) } else { ctx.Flash.Success(ctx.Tr("admin.notices.delete_success")) - ctx.Status(200) + ctx.Status(http.StatusOK) } } diff --git a/routers/web/auth/oauth.go b/routers/web/auth/oauth.go index 847af52bdb..4369c333ac 100644 --- a/routers/web/auth/oauth.go +++ b/routers/web/auth/oauth.go @@ -462,7 +462,7 @@ func AuthorizeOAuth(ctx *context.Context) { log.Error("Unable to update nonce: %v", err) } } - ctx.Redirect(redirect.String(), 302) + ctx.Redirect(redirect.String()) return } @@ -544,7 +544,7 @@ func GrantApplicationOAuth(ctx *context.Context) { handleServerError(ctx, form.State, form.RedirectURI) return } - ctx.Redirect(redirect.String(), 302) + ctx.Redirect(redirect.String(), http.StatusSeeOther) } // OIDCWellKnown generates JSON so OIDC clients know Gitea's capabilities @@ -752,7 +752,7 @@ func handleAuthorizeError(ctx *context.Context, authErr AuthorizeError, redirect if redirectURI == "" { log.Warn("Authorization failed: %v", authErr.ErrorDescription) ctx.Data["Error"] = authErr - ctx.HTML(400, tplGrantError) + ctx.HTML(http.StatusBadRequest, tplGrantError) return } redirect, err := url.Parse(redirectURI) @@ -765,7 +765,7 @@ func handleAuthorizeError(ctx *context.Context, authErr AuthorizeError, redirect q.Set("error_description", authErr.ErrorDescription) q.Set("state", authErr.State) redirect.RawQuery = q.Encode() - ctx.Redirect(redirect.String(), 302) + ctx.Redirect(redirect.String(), http.StatusSeeOther) } // SignInOAuth handles the OAuth2 login buttons diff --git a/routers/web/auth/webauthn.go b/routers/web/auth/webauthn.go index bedbe7ddc3..c0cf58f3d3 100644 --- a/routers/web/auth/webauthn.go +++ b/routers/web/auth/webauthn.go @@ -39,7 +39,7 @@ func WebAuthn(ctx *context.Context) { return } - ctx.HTML(200, tplWebAuthn) + ctx.HTML(http.StatusOK, tplWebAuthn) } // WebAuthnLoginAssertion submits a WebAuthn challenge to the browser @@ -166,5 +166,5 @@ func WebAuthnLoginAssertionPost(ctx *context.Context) { } } - ctx.JSON(200, map[string]string{"redirect": redirect}) + ctx.JSON(http.StatusOK, map[string]string{"redirect": redirect}) } 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) } diff --git a/routers/web/explore/code.go b/routers/web/explore/code.go index 506d13b59b..28bdc7c9ca 100644 --- a/routers/web/explore/code.go +++ b/routers/web/explore/code.go @@ -24,7 +24,7 @@ const ( // Code render explore code page func Code(ctx *context.Context) { if !setting.Indexer.RepoIndexerEnabled { - ctx.Redirect(setting.AppSubURL+"/explore", 302) + ctx.Redirect(setting.AppSubURL + "/explore") return } diff --git a/routers/web/goget.go b/routers/web/goget.go index 2843a96c30..4a31fcc2c5 100644 --- a/routers/web/goget.go +++ b/routers/web/goget.go @@ -48,7 +48,7 @@ func goGet(ctx *context.Context) { </body> </html> `)) - ctx.Status(400) + ctx.Status(http.StatusBadRequest) return } branchName := setting.Repository.DefaultBranch diff --git a/routers/web/metrics.go b/routers/web/metrics.go index 37558ee337..c7e01b8faa 100644 --- a/routers/web/metrics.go +++ b/routers/web/metrics.go @@ -21,13 +21,13 @@ func Metrics(resp http.ResponseWriter, req *http.Request) { } header := req.Header.Get("Authorization") if header == "" { - http.Error(resp, "", 401) + http.Error(resp, "", http.StatusUnauthorized) return } got := []byte(header) want := []byte("Bearer " + setting.Metrics.Token) if subtle.ConstantTimeCompare(got, want) != 1 { - http.Error(resp, "", 401) + http.Error(resp, "", http.StatusUnauthorized) return } promhttp.Handler().ServeHTTP(resp, req) diff --git a/routers/web/repo/editor.go b/routers/web/repo/editor.go index a2cf070375..c10162c759 100644 --- a/routers/web/repo/editor.go +++ b/routers/web/repo/editor.go @@ -780,7 +780,7 @@ func UploadFileToServer(ctx *context.Context) { func RemoveUploadFileFromServer(ctx *context.Context) { form := web.GetForm(ctx).(*forms.RemoveUploadFileForm) if len(form.File) == 0 { - ctx.Status(204) + ctx.Status(http.StatusNoContent) return } @@ -790,7 +790,7 @@ func RemoveUploadFileFromServer(ctx *context.Context) { } log.Trace("Upload file removed: %s", form.File) - ctx.Status(204) + ctx.Status(http.StatusNoContent) } // GetUniquePatchBranchName Gets a unique branch name for a new patch branch diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index adf7e93eac..aeb1f0a020 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -1931,7 +1931,7 @@ func UpdatePullReviewRequest(ctx *context.Context) { // TODO: Not support 'clear' now if action != "attach" && action != "detach" { - ctx.Status(403) + ctx.Status(http.StatusForbidden) return } @@ -1946,7 +1946,7 @@ func UpdatePullReviewRequest(ctx *context.Context) { "UpdatePullReviewRequest: refusing to add review request for non-PR issue %-v#%d", issue.Repo, issue.Index, ) - ctx.Status(403) + ctx.Status(http.StatusForbidden) return } if reviewID < 0 { @@ -1961,7 +1961,7 @@ func UpdatePullReviewRequest(ctx *context.Context) { "UpdatePullReviewRequest: refusing to add team review request for %s#%d owned by non organization UID[%d]", issue.Repo.FullName(), issue.Index, issue.Repo.ID, ) - ctx.Status(403) + ctx.Status(http.StatusForbidden) return } @@ -1975,7 +1975,7 @@ func UpdatePullReviewRequest(ctx *context.Context) { log.Warn( "UpdatePullReviewRequest: refusing to add team review request for UID[%d] team %s to %s#%d owned by UID[%d]", team.OrgID, team.Name, issue.Repo.FullName(), issue.Index, issue.Repo.ID) - ctx.Status(403) + ctx.Status(http.StatusForbidden) return } @@ -1987,7 +1987,7 @@ func UpdatePullReviewRequest(ctx *context.Context) { team.OrgID, team.Name, issue.Repo.FullName(), issue.Index, issue.Repo.ID, err, ) - ctx.Status(403) + ctx.Status(http.StatusForbidden) return } ctx.ServerError("IsValidTeamReviewRequest", err) @@ -2010,7 +2010,7 @@ func UpdatePullReviewRequest(ctx *context.Context) { reviewID, issue.Repo, issue.Index, err, ) - ctx.Status(403) + ctx.Status(http.StatusForbidden) return } ctx.ServerError("GetUserByID", err) @@ -2025,7 +2025,7 @@ func UpdatePullReviewRequest(ctx *context.Context) { reviewer, issue.Repo, issue.Index, err, ) - ctx.Status(403) + ctx.Status(http.StatusForbidden) return } ctx.ServerError("isValidReviewRequest", err) @@ -2117,7 +2117,7 @@ func NewComment(ctx *context.Context) { if issue.IsLocked && !ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull) && !ctx.Doer.IsAdmin { ctx.Flash.Error(ctx.Tr("repo.issues.comment_on_locked")) - ctx.Redirect(issue.HTMLURL(), http.StatusSeeOther) + ctx.Redirect(issue.HTMLURL()) return } @@ -2170,10 +2170,10 @@ func NewComment(ctx *context.Context) { if models.IsErrDependenciesLeft(err) { if issue.IsPull { ctx.Flash.Error(ctx.Tr("repo.issues.dependency.pr_close_blocked")) - ctx.Redirect(fmt.Sprintf("%s/pulls/%d", ctx.Repo.RepoLink, issue.Index), http.StatusSeeOther) + ctx.Redirect(fmt.Sprintf("%s/pulls/%d", ctx.Repo.RepoLink, issue.Index)) } else { ctx.Flash.Error(ctx.Tr("repo.issues.dependency.issue_close_blocked")) - ctx.Redirect(fmt.Sprintf("%s/issues/%d", ctx.Repo.RepoLink, issue.Index), http.StatusSeeOther) + ctx.Redirect(fmt.Sprintf("%s/issues/%d", ctx.Repo.RepoLink, issue.Index)) } return } @@ -2306,7 +2306,7 @@ func DeleteComment(ctx *context.Context) { return } - ctx.Status(200) + ctx.Status(http.StatusOK) } // ChangeIssueReaction create a reaction for issue diff --git a/routers/web/repo/issue_dependency.go b/routers/web/repo/issue_dependency.go index d9084328ee..d43cb373a2 100644 --- a/routers/web/repo/issue_dependency.go +++ b/routers/web/repo/issue_dependency.go @@ -35,7 +35,7 @@ func AddDependency(ctx *context.Context) { } // Redirect - defer ctx.Redirect(issue.HTMLURL(), http.StatusSeeOther) + defer ctx.Redirect(issue.HTMLURL()) // Dependency dep, err := models.GetIssueByID(depID) @@ -125,5 +125,5 @@ func RemoveDependency(ctx *context.Context) { } // Redirect - ctx.Redirect(issue.HTMLURL(), http.StatusSeeOther) + ctx.Redirect(issue.HTMLURL()) } diff --git a/routers/web/repo/issue_label_test.go b/routers/web/repo/issue_label_test.go index baa34530fa..5d7a29ee93 100644 --- a/routers/web/repo/issue_label_test.go +++ b/routers/web/repo/issue_label_test.go @@ -36,7 +36,7 @@ func TestInitializeLabels(t *testing.T) { test.LoadRepo(t, ctx, 2) web.SetForm(ctx, &forms.InitializeLabelsForm{TemplateName: "Default"}) InitializeLabels(ctx) - assert.EqualValues(t, http.StatusFound, ctx.Resp.Status()) + assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status()) unittest.AssertExistsAndLoadBean(t, &models.Label{ RepoID: 2, Name: "enhancement", @@ -82,7 +82,7 @@ func TestNewLabel(t *testing.T) { Color: "#abcdef", }) NewLabel(ctx) - assert.EqualValues(t, http.StatusFound, ctx.Resp.Status()) + assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status()) unittest.AssertExistsAndLoadBean(t, &models.Label{ Name: "newlabel", Color: "#abcdef", @@ -101,7 +101,7 @@ func TestUpdateLabel(t *testing.T) { Color: "#abcdef", }) UpdateLabel(ctx) - assert.EqualValues(t, http.StatusFound, ctx.Resp.Status()) + assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status()) unittest.AssertExistsAndLoadBean(t, &models.Label{ ID: 2, Name: "newnameforlabel", diff --git a/routers/web/repo/issue_lock.go b/routers/web/repo/issue_lock.go index b016818669..5ac5cac52e 100644 --- a/routers/web/repo/issue_lock.go +++ b/routers/web/repo/issue_lock.go @@ -5,8 +5,6 @@ package repo import ( - "net/http" - "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/web" @@ -43,7 +41,7 @@ func LockIssue(ctx *context.Context) { return } - ctx.Redirect(issue.HTMLURL(), http.StatusSeeOther) + ctx.Redirect(issue.HTMLURL()) } // UnlockIssue unlocks a previously locked issue. @@ -67,5 +65,5 @@ func UnlockIssue(ctx *context.Context) { return } - ctx.Redirect(issue.HTMLURL(), http.StatusSeeOther) + ctx.Redirect(issue.HTMLURL()) } diff --git a/routers/web/repo/issue_watch.go b/routers/web/repo/issue_watch.go index 223fc72071..53fec11cdc 100644 --- a/routers/web/repo/issue_watch.go +++ b/routers/web/repo/issue_watch.go @@ -53,5 +53,5 @@ func IssueWatch(ctx *context.Context) { return } - ctx.Redirect(issue.HTMLURL(), http.StatusSeeOther) + ctx.Redirect(issue.HTMLURL()) } diff --git a/routers/web/repo/search.go b/routers/web/repo/search.go index e33fe38dea..c230e88d2d 100644 --- a/routers/web/repo/search.go +++ b/routers/web/repo/search.go @@ -18,7 +18,7 @@ const tplSearch base.TplName = "repo/search" // Search render repository search page func Search(ctx *context.Context) { if !setting.Indexer.RepoIndexerEnabled { - ctx.Redirect(ctx.Repo.RepoLink, 302) + ctx.Redirect(ctx.Repo.RepoLink) return } language := ctx.FormTrim("l") diff --git a/routers/web/repo/setting_protected_branch.go b/routers/web/repo/setting_protected_branch.go index cd6cf38038..dae618a758 100644 --- a/routers/web/repo/setting_protected_branch.go +++ b/routers/web/repo/setting_protected_branch.go @@ -73,7 +73,7 @@ func ProtectedBranchPost(ctx *context.Context) { branch := ctx.FormString("branch") if !ctx.Repo.GitRepo.IsBranchExist(branch) { - ctx.Status(404) + ctx.Status(http.StatusNotFound) return } else if repo.DefaultBranch != branch { repo.DefaultBranch = branch diff --git a/routers/web/repo/settings_test.go b/routers/web/repo/settings_test.go index bd29eca195..db1e905869 100644 --- a/routers/web/repo/settings_test.go +++ b/routers/web/repo/settings_test.go @@ -60,7 +60,7 @@ func TestAddReadOnlyDeployKey(t *testing.T) { } web.SetForm(ctx, &addKeyForm) DeployKeysPost(ctx) - assert.EqualValues(t, http.StatusFound, ctx.Resp.Status()) + assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status()) unittest.AssertExistsAndLoadBean(t, &asymkey_model.DeployKey{ Name: addKeyForm.Title, @@ -90,7 +90,7 @@ func TestAddReadWriteOnlyDeployKey(t *testing.T) { } web.SetForm(ctx, &addKeyForm) DeployKeysPost(ctx) - assert.EqualValues(t, http.StatusFound, ctx.Resp.Status()) + assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status()) unittest.AssertExistsAndLoadBean(t, &asymkey_model.DeployKey{ Name: addKeyForm.Title, @@ -127,7 +127,7 @@ func TestCollaborationPost(t *testing.T) { CollaborationPost(ctx) - assert.EqualValues(t, http.StatusFound, ctx.Resp.Status()) + assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status()) exists, err := models.IsCollaborator(re.ID, 4) assert.NoError(t, err) @@ -153,7 +153,7 @@ func TestCollaborationPost_InactiveUser(t *testing.T) { CollaborationPost(ctx) - assert.EqualValues(t, http.StatusFound, ctx.Resp.Status()) + assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status()) assert.NotEmpty(t, ctx.Flash.ErrorMsg) } @@ -185,7 +185,7 @@ func TestCollaborationPost_AddCollaboratorTwice(t *testing.T) { CollaborationPost(ctx) - assert.EqualValues(t, http.StatusFound, ctx.Resp.Status()) + assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status()) exists, err := models.IsCollaborator(re.ID, 4) assert.NoError(t, err) @@ -194,7 +194,7 @@ func TestCollaborationPost_AddCollaboratorTwice(t *testing.T) { // Try adding the same collaborator again CollaborationPost(ctx) - assert.EqualValues(t, http.StatusFound, ctx.Resp.Status()) + assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status()) assert.NotEmpty(t, ctx.Flash.ErrorMsg) } @@ -216,7 +216,7 @@ func TestCollaborationPost_NonExistentUser(t *testing.T) { CollaborationPost(ctx) - assert.EqualValues(t, http.StatusFound, ctx.Resp.Status()) + assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status()) assert.NotEmpty(t, ctx.Flash.ErrorMsg) } @@ -256,7 +256,7 @@ func TestAddTeamPost(t *testing.T) { AddTeamPost(ctx) assert.True(t, team.HasRepository(re.ID)) - assert.EqualValues(t, http.StatusFound, ctx.Resp.Status()) + assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status()) assert.Empty(t, ctx.Flash.ErrorMsg) } @@ -296,7 +296,7 @@ func TestAddTeamPost_NotAllowed(t *testing.T) { AddTeamPost(ctx) assert.False(t, team.HasRepository(re.ID)) - assert.EqualValues(t, http.StatusFound, ctx.Resp.Status()) + assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status()) assert.NotEmpty(t, ctx.Flash.ErrorMsg) } @@ -337,7 +337,7 @@ func TestAddTeamPost_AddTeamTwice(t *testing.T) { AddTeamPost(ctx) assert.True(t, team.HasRepository(re.ID)) - assert.EqualValues(t, http.StatusFound, ctx.Resp.Status()) + assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status()) assert.NotEmpty(t, ctx.Flash.ErrorMsg) } @@ -370,7 +370,7 @@ func TestAddTeamPost_NonExistentTeam(t *testing.T) { ctx.Repo = repo AddTeamPost(ctx) - assert.EqualValues(t, http.StatusFound, ctx.Resp.Status()) + assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status()) assert.NotEmpty(t, ctx.Flash.ErrorMsg) } diff --git a/routers/web/repo/webhook.go b/routers/web/repo/webhook.go index 7ffea1724a..81dab5a3b9 100644 --- a/routers/web/repo/webhook.go +++ b/routers/web/repo/webhook.go @@ -1241,7 +1241,7 @@ func TestWebhook(ctx *context.Context) { w, err := webhook.GetWebhookByRepoID(ctx.Repo.Repository.ID, hookID) if err != nil { ctx.Flash.Error("GetWebhookByID: " + err.Error()) - ctx.Status(500) + ctx.Status(http.StatusInternalServerError) return } @@ -1285,10 +1285,10 @@ func TestWebhook(ctx *context.Context) { } if err := webhook_service.PrepareWebhook(w, ctx.Repo.Repository, webhook.HookEventPush, p); err != nil { ctx.Flash.Error("PrepareWebhook: " + err.Error()) - ctx.Status(500) + ctx.Status(http.StatusInternalServerError) } else { ctx.Flash.Info(ctx.Tr("repo.settings.webhook.delivery.success")) - ctx.Status(200) + ctx.Status(http.StatusOK) } } diff --git a/routers/web/repo/wiki_test.go b/routers/web/repo/wiki_test.go index b19c628a9f..41b5c0f8fd 100644 --- a/routers/web/repo/wiki_test.go +++ b/routers/web/repo/wiki_test.go @@ -124,7 +124,7 @@ func TestNewWikiPost(t *testing.T) { Message: message, }) NewWikiPost(ctx) - assert.EqualValues(t, http.StatusFound, ctx.Resp.Status()) + assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status()) assertWikiExists(t, ctx.Repo.Repository, title) assert.Equal(t, wikiContent(t, ctx.Repo.Repository, title), content) } @@ -176,7 +176,7 @@ func TestEditWikiPost(t *testing.T) { Message: message, }) EditWikiPost(ctx) - assert.EqualValues(t, http.StatusFound, ctx.Resp.Status()) + assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status()) assertWikiExists(t, ctx.Repo.Repository, title) assert.Equal(t, wikiContent(t, ctx.Repo.Repository, title), content) if title != "Home" { diff --git a/routers/web/user/home.go b/routers/web/user/home.go index afdc344b69..0878e8d528 100644 --- a/routers/web/user/home.go +++ b/routers/web/user/home.go @@ -151,7 +151,7 @@ func Dashboard(ctx *context.Context) { func Milestones(ctx *context.Context) { if unit.TypeIssues.UnitGlobalDisabled() && unit.TypePullRequests.UnitGlobalDisabled() { log.Debug("Milestones overview page not available as both issues and pull requests are globally disabled") - ctx.Status(404) + ctx.Status(http.StatusNotFound) return } @@ -323,7 +323,7 @@ func Milestones(ctx *context.Context) { func Pulls(ctx *context.Context) { if unit.TypePullRequests.UnitGlobalDisabled() { log.Debug("Pull request overview page not available as it is globally disabled.") - ctx.Status(404) + ctx.Status(http.StatusNotFound) return } @@ -336,7 +336,7 @@ func Pulls(ctx *context.Context) { func Issues(ctx *context.Context) { if unit.TypeIssues.UnitGlobalDisabled() { log.Debug("Issues overview page not available as it is globally disabled.") - ctx.Status(404) + ctx.Status(http.StatusNotFound) return } diff --git a/routers/web/user/setting/account_test.go b/routers/web/user/setting/account_test.go index a67d09e9ed..005603e7ac 100644 --- a/routers/web/user/setting/account_test.go +++ b/routers/web/user/setting/account_test.go @@ -94,6 +94,6 @@ func TestChangePassword(t *testing.T) { AccountPost(ctx) assert.Contains(t, ctx.Flash.ErrorMsg, req.Message) - assert.EqualValues(t, http.StatusFound, ctx.Resp.Status()) + assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status()) } } diff --git a/routers/web/web.go b/routers/web/web.go index 6d2fbedace..b40a43058d 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -96,7 +96,7 @@ func Routes(sessioner func(http.Handler) http.Handler) *web.Route { // this png is very likely to always be below the limit for gzip so it doesn't need to pass through gzip routes.Get("/apple-touch-icon.png", func(w http.ResponseWriter, req *http.Request) { - http.Redirect(w, req, path.Join(setting.StaticURLPrefix, "/assets/img/apple-touch-icon.png"), 301) + http.Redirect(w, req, path.Join(setting.StaticURLPrefix, "/assets/img/apple-touch-icon.png"), http.StatusPermanentRedirect) }) // redirect default favicon to the path of the custom favicon with a default as a fallback @@ -142,17 +142,17 @@ func Routes(sessioner func(http.Handler) http.Handler) *web.Route { routes.Get("/ssh_info", func(rw http.ResponseWriter, req *http.Request) { if !git.SupportProcReceive { - rw.WriteHeader(404) + rw.WriteHeader(http.StatusNotFound) return } rw.Header().Set("content-type", "text/json;charset=UTF-8") _, err := rw.Write([]byte(`{"type":"gitea","version":1}`)) if err != nil { log.Error("fail to write result: err: %v", err) - rw.WriteHeader(500) + rw.WriteHeader(http.StatusInternalServerError) return } - rw.WriteHeader(200) + rw.WriteHeader(http.StatusOK) }) // Removed: toolbox.Toolboxer middleware will provide debug information which seems unnecessary |