code.gitea.io/gitea@v1.22.3/routers/web/githttp.go (about) 1 // Copyright 2023 The Gitea Authors. All rights reserved. 2 // SPDX-License-Identifier: MIT 3 4 package web 5 6 import ( 7 "net/http" 8 9 "code.gitea.io/gitea/modules/setting" 10 "code.gitea.io/gitea/modules/web" 11 "code.gitea.io/gitea/routers/web/repo" 12 "code.gitea.io/gitea/services/context" 13 ) 14 15 func requireSignIn(ctx *context.Context) { 16 if !setting.Service.RequireSignInView { 17 return 18 } 19 20 // rely on the results of Contexter 21 if !ctx.IsSigned { 22 // TODO: support digit auth - which would be Authorization header with digit 23 ctx.Resp.Header().Set("WWW-Authenticate", `Basic realm="Gitea"`) 24 ctx.Error(http.StatusUnauthorized) 25 } 26 } 27 28 func gitHTTPRouters(m *web.Route) { 29 m.Group("", func() { 30 m.Methods("POST,OPTIONS", "/git-upload-pack", repo.ServiceUploadPack) 31 m.Methods("POST,OPTIONS", "/git-receive-pack", repo.ServiceReceivePack) 32 m.Methods("GET,OPTIONS", "/info/refs", repo.GetInfoRefs) 33 m.Methods("GET,OPTIONS", "/HEAD", repo.GetTextFile("HEAD")) 34 m.Methods("GET,OPTIONS", "/objects/info/alternates", repo.GetTextFile("objects/info/alternates")) 35 m.Methods("GET,OPTIONS", "/objects/info/http-alternates", repo.GetTextFile("objects/info/http-alternates")) 36 m.Methods("GET,OPTIONS", "/objects/info/packs", repo.GetInfoPacks) 37 m.Methods("GET,OPTIONS", "/objects/info/{file:[^/]*}", repo.GetTextFile("")) 38 m.Methods("GET,OPTIONS", "/objects/{head:[0-9a-f]{2}}/{hash:[0-9a-f]{38,62}}", repo.GetLooseObject) 39 m.Methods("GET,OPTIONS", "/objects/pack/pack-{file:[0-9a-f]{40,64}}.pack", repo.GetPackFile) 40 m.Methods("GET,OPTIONS", "/objects/pack/pack-{file:[0-9a-f]{40,64}}.idx", repo.GetIdxFile) 41 }, ignSignInAndCsrf, requireSignIn, repo.HTTPGitEnabledHandler, repo.CorsHandler(), context.UserAssignmentWeb()) 42 }