mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Update HTTP status codes to modern codes (#18063)
* 2xx/3xx/4xx/5xx -> http.Status... * http.StatusFound -> http.StatusTemporaryRedirect * http.StatusMovedPermanently -> http.StatusPermanentRedirect
This commit is contained in:
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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())
|
||||
}
|
||||
|
@@ -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",
|
||||
|
@@ -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())
|
||||
}
|
||||
|
@@ -53,5 +53,5 @@ func IssueWatch(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Redirect(issue.HTMLURL(), http.StatusSeeOther)
|
||||
ctx.Redirect(issue.HTMLURL())
|
||||
}
|
||||
|
@@ -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")
|
||||
|
@@ -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
|
||||
|
@@ -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)
|
||||
}
|
||||
|
||||
|
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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" {
|
||||
|
Reference in New Issue
Block a user