Skip to content

Commit 3f280f8

Browse files
authored
Update HTTP status codes to modern codes (#18063)
* 2xx/3xx/4xx/5xx -> http.Status... * http.StatusFound -> http.StatusTemporaryRedirect * http.StatusMovedPermanently -> http.StatusPermanentRedirect
1 parent 395117d commit 3f280f8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+211
-212
lines changed

cmd/web_acme.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,5 +128,5 @@ func runLetsEncryptFallbackHandler(w http.ResponseWriter, r *http.Request) {
128128
// URI always contains a leading slash, which would result in a double
129129
// slash
130130
target := strings.TrimSuffix(setting.AppURL, "/") + r.URL.RequestURI()
131-
http.Redirect(w, r, target, http.StatusFound)
131+
http.Redirect(w, r, target, http.StatusTemporaryRedirect)
132132
}

integrations/admin_user_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func TestAdminEditUser(t *testing.T) {
4646
}
4747

4848
func testSuccessfullEdit(t *testing.T, formData user_model.User) {
49-
makeRequest(t, formData, http.StatusFound)
49+
makeRequest(t, formData, http.StatusSeeOther)
5050
}
5151

5252
func makeRequest(t *testing.T, formData user_model.User, headerCode int) {

integrations/api_branch_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func testAPIGetBranchProtection(t *testing.T, branchName string, expectedHTTPSta
3737
req := NewRequestf(t, "GET", "/api/v1/repos/user2/repo1/branch_protections/%s?token=%s", branchName, token)
3838
resp := session.MakeRequest(t, req, expectedHTTPStatus)
3939

40-
if resp.Code == 200 {
40+
if resp.Code == http.StatusOK {
4141
var branchProtection api.BranchProtection
4242
DecodeJSON(t, resp, &branchProtection)
4343
assert.EqualValues(t, branchName, branchProtection.BranchName)
@@ -52,7 +52,7 @@ func testAPICreateBranchProtection(t *testing.T, branchName string, expectedHTTP
5252
})
5353
resp := session.MakeRequest(t, req, expectedHTTPStatus)
5454

55-
if resp.Code == 201 {
55+
if resp.Code == http.StatusCreated {
5656
var branchProtection api.BranchProtection
5757
DecodeJSON(t, resp, &branchProtection)
5858
assert.EqualValues(t, branchName, branchProtection.BranchName)
@@ -65,7 +65,7 @@ func testAPIEditBranchProtection(t *testing.T, branchName string, body *api.Bran
6565
req := NewRequestWithJSON(t, "PATCH", "/api/v1/repos/user2/repo1/branch_protections/"+branchName+"?token="+token, body)
6666
resp := session.MakeRequest(t, req, expectedHTTPStatus)
6767

68-
if resp.Code == 200 {
68+
if resp.Code == http.StatusOK {
6969
var branchProtection api.BranchProtection
7070
DecodeJSON(t, resp, &branchProtection)
7171
assert.EqualValues(t, branchName, branchProtection.BranchName)

integrations/api_helper_for_declarative_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ func doAPICreatePullRequest(ctx APITestContext, owner, repo, baseBranch, headBra
227227
Title: fmt.Sprintf("create a pr from %s to %s", headBranch, baseBranch),
228228
})
229229

230-
expected := 201
230+
expected := http.StatusCreated
231231
if ctx.ExpectedCode != 0 {
232232
expected = ctx.ExpectedCode
233233
}
@@ -246,7 +246,7 @@ func doAPIGetPullRequest(ctx APITestContext, owner, repo string, index int64) fu
246246
owner, repo, index, ctx.Token)
247247
req := NewRequest(t, http.MethodGet, urlStr)
248248

249-
expected := 200
249+
expected := http.StatusOK
250250
if ctx.ExpectedCode != 0 {
251251
expected = ctx.ExpectedCode
252252
}
@@ -287,7 +287,7 @@ func doAPIMergePullRequest(ctx APITestContext, owner, repo string, index int64)
287287

288288
expected := ctx.ExpectedCode
289289
if expected == 0 {
290-
expected = 200
290+
expected = http.StatusOK
291291
}
292292

293293
if !assert.EqualValues(t, expected, resp.Code,
@@ -310,7 +310,7 @@ func doAPIManuallyMergePullRequest(ctx APITestContext, owner, repo, commitID str
310310
ctx.Session.MakeRequest(t, req, ctx.ExpectedCode)
311311
return
312312
}
313-
ctx.Session.MakeRequest(t, req, 200)
313+
ctx.Session.MakeRequest(t, req, http.StatusOK)
314314
}
315315
}
316316

integrations/api_pull_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func TestAPICreatePullSuccess(t *testing.T) {
7777
Base: "master",
7878
Title: "create a failure pr",
7979
})
80-
session.MakeRequest(t, req, 201)
80+
session.MakeRequest(t, req, http.StatusCreated)
8181
session.MakeRequest(t, req, http.StatusUnprocessableEntity) // second request should fail
8282
}
8383

@@ -105,7 +105,7 @@ func TestAPICreatePullWithFieldsSuccess(t *testing.T) {
105105

106106
req := NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls?token=%s", owner10.Name, repo10.Name, token), opts)
107107

108-
res := session.MakeRequest(t, req, 201)
108+
res := session.MakeRequest(t, req, http.StatusCreated)
109109
pull := new(api.PullRequest)
110110
DecodeJSON(t, res, pull)
111111

@@ -165,20 +165,20 @@ func TestAPIEditPull(t *testing.T) {
165165
Title: "create a success pr",
166166
})
167167
pull := new(api.PullRequest)
168-
resp := session.MakeRequest(t, req, 201)
168+
resp := session.MakeRequest(t, req, http.StatusCreated)
169169
DecodeJSON(t, resp, pull)
170170
assert.EqualValues(t, "master", pull.Base.Name)
171171

172172
req = NewRequestWithJSON(t, http.MethodPatch, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d?token=%s", owner10.Name, repo10.Name, pull.Index, token), &api.EditPullRequestOption{
173173
Base: "feature/1",
174174
Title: "edit a this pr",
175175
})
176-
resp = session.MakeRequest(t, req, 201)
176+
resp = session.MakeRequest(t, req, http.StatusCreated)
177177
DecodeJSON(t, resp, pull)
178178
assert.EqualValues(t, "feature/1", pull.Base.Name)
179179

180180
req = NewRequestWithJSON(t, http.MethodPatch, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d?token=%s", owner10.Name, repo10.Name, pull.Index, token), &api.EditPullRequestOption{
181181
Base: "not-exist",
182182
})
183-
session.MakeRequest(t, req, 404)
183+
session.MakeRequest(t, req, http.StatusNotFound)
184184
}

integrations/api_repo_languages_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func TestRepoLanguages(t *testing.T) {
3333
"content": "package main",
3434
"commit_choice": "direct",
3535
})
36-
session.MakeRequest(t, req, http.StatusFound)
36+
session.MakeRequest(t, req, http.StatusSeeOther)
3737

3838
// let gitea calculate language stats
3939
time.Sleep(time.Second)

integrations/attachment_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func createAttachment(t *testing.T, session *TestSession, repoURL, filename stri
5959
func TestCreateAnonymousAttachment(t *testing.T) {
6060
defer prepareTestEnv(t)()
6161
session := emptyTestSession(t)
62-
createAttachment(t, session, "user2/repo1", "image.png", generateImg(), http.StatusFound)
62+
createAttachment(t, session, "user2/repo1", "image.png", generateImg(), http.StatusSeeOther)
6363
}
6464

6565
func TestCreateIssueAttachment(t *testing.T) {
@@ -83,7 +83,7 @@ func TestCreateIssueAttachment(t *testing.T) {
8383
}
8484

8585
req = NewRequestWithValues(t, "POST", link, postData)
86-
resp = session.MakeRequest(t, req, http.StatusFound)
86+
resp = session.MakeRequest(t, req, http.StatusSeeOther)
8787
test.RedirectURL(resp) // check that redirect URL exists
8888

8989
// Validate that attachment is available

integrations/auth_ldap_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func addAuthSourceLDAP(t *testing.T, sshKeyAttribute string, groupMapParams ...s
135135
"group_team_map_removal": groupTeamMapRemoval,
136136
"user_uid": "DN",
137137
})
138-
session.MakeRequest(t, req, http.StatusFound)
138+
session.MakeRequest(t, req, http.StatusSeeOther)
139139
}
140140

141141
func TestLDAPUserSignin(t *testing.T) {
@@ -202,7 +202,7 @@ func TestLDAPAuthChange(t *testing.T) {
202202
"is_sync_enabled": "on",
203203
"is_active": "on",
204204
})
205-
session.MakeRequest(t, req, http.StatusFound)
205+
session.MakeRequest(t, req, http.StatusSeeOther)
206206

207207
req = NewRequest(t, "GET", href)
208208
resp = session.MakeRequest(t, req, http.StatusOK)

integrations/change_default_branch_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func TestChangeDefaultBranch(t *testing.T) {
2828
"action": "default_branch",
2929
"branch": "DefaultBranch",
3030
})
31-
session.MakeRequest(t, req, http.StatusFound)
31+
session.MakeRequest(t, req, http.StatusSeeOther)
3232

3333
csrf = GetCSRF(t, session, branchesURL)
3434
req = NewRequestWithValues(t, "POST", branchesURL, map[string]string{

integrations/create_no_session_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func TestSessionFileCreation(t *testing.T) {
110110
"user_name": "user2",
111111
"password": userPassword,
112112
})
113-
resp = MakeRequest(t, req, http.StatusFound)
113+
resp = MakeRequest(t, req, http.StatusSeeOther)
114114
sessionID = getSessionID(t, resp)
115115

116116
assert.FileExists(t, sessionFile(tmpDir, sessionID))

0 commit comments

Comments
 (0)