Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

githttp.go 1.7KB

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