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:
KN4CK3R 2022-03-23 05:54:07 +01:00 committed by GitHub
parent 395117d301
commit 3f280f89e7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
76 changed files with 211 additions and 212 deletions

View file

@ -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

View file

@ -288,7 +288,7 @@ func ResetIssueTime(ctx *context.APIContext) {
}
return
}
ctx.Status(204)
ctx.Status(http.StatusNoContent)
}
// DeleteTime delete a specific time by id

View file

@ -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)
}
}
}()

View file

@ -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)

View file

@ -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)
}

View file

@ -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 {

View file

@ -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)
}
}

View file

@ -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

View file

@ -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})
}

View file

@ -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)
}

View file

@ -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
}

View file

@ -48,7 +48,7 @@ func goGet(ctx *context.Context) {
</body>
</html>
`))
ctx.Status(400)
ctx.Status(http.StatusBadRequest)
return
}
branchName := setting.Repository.DefaultBranch

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -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())
}

View file

@ -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",

View file

@ -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())
}

View file

@ -53,5 +53,5 @@ func IssueWatch(ctx *context.Context) {
return
}
ctx.Redirect(issue.HTMLURL(), http.StatusSeeOther)
ctx.Redirect(issue.HTMLURL())
}

View file

@ -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")

View file

@ -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

View file

@ -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)
}

View file

@ -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)
}
}

View file

@ -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" {

View file

@ -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
}

View file

@ -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())
}
}

View file

@ -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