aboutsummaryrefslogtreecommitdiffstats
path: root/routers/web/githttp.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2023-11-02 22:14:33 +0800
committerGitHub <noreply@github.com>2023-11-02 22:14:33 +0800
commit0ba4ecc3bd8443f0d3a834530a44e0c1334554b7 (patch)
tree84e60c264cc1afa7d8d884030d688b9ccaac2432 /routers/web/githttp.go
parent4776fde9e1caa7cee5671715144a668e19a0323c (diff)
downloadgitea-0ba4ecc3bd8443f0d3a834530a44e0c1334554b7.tar.gz
gitea-0ba4ecc3bd8443f0d3a834530a44e0c1334554b7.zip
Fix http protocol auth (#27875)
Diffstat (limited to 'routers/web/githttp.go')
-rw-r--r--routers/web/githttp.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/routers/web/githttp.go b/routers/web/githttp.go
new file mode 100644
index 0000000000..b2fb5b472f
--- /dev/null
+++ b/routers/web/githttp.go
@@ -0,0 +1,43 @@
+// Copyright 2023 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package web
+
+import (
+ "net/http"
+
+ "code.gitea.io/gitea/modules/context"
+ "code.gitea.io/gitea/modules/setting"
+ "code.gitea.io/gitea/modules/web"
+ "code.gitea.io/gitea/routers/web/repo"
+ context_service "code.gitea.io/gitea/services/context"
+)
+
+func requireSignIn(ctx *context.Context) {
+ if !setting.Service.RequireSignInView {
+ return
+ }
+
+ // rely on the results of Contexter
+ if !ctx.IsSigned {
+ // TODO: support digit auth - which would be Authorization header with digit
+ ctx.Resp.Header().Set("WWW-Authenticate", `Basic realm="Gitea"`)
+ ctx.Error(http.StatusUnauthorized)
+ }
+}
+
+func gitHTTPRouters(m *web.Route) {
+ m.Group("", func() {
+ m.PostOptions("/git-upload-pack", repo.ServiceUploadPack)
+ m.PostOptions("/git-receive-pack", repo.ServiceReceivePack)
+ m.GetOptions("/info/refs", repo.GetInfoRefs)
+ m.GetOptions("/HEAD", repo.GetTextFile("HEAD"))
+ m.GetOptions("/objects/info/alternates", repo.GetTextFile("objects/info/alternates"))
+ m.GetOptions("/objects/info/http-alternates", repo.GetTextFile("objects/info/http-alternates"))
+ m.GetOptions("/objects/info/packs", repo.GetInfoPacks)
+ m.GetOptions("/objects/info/{file:[^/]*}", repo.GetTextFile(""))
+ m.GetOptions("/objects/{head:[0-9a-f]{2}}/{hash:[0-9a-f]{38}}", repo.GetLooseObject)
+ m.GetOptions("/objects/pack/pack-{file:[0-9a-f]{40}}.pack", repo.GetPackFile)
+ m.GetOptions("/objects/pack/pack-{file:[0-9a-f]{40}}.idx", repo.GetIdxFile)
+ }, ignSignInAndCsrf, requireSignIn, repo.HTTPGitEnabledHandler, repo.CorsHandler(), context_service.UserAssignmentWeb())
+}