You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

githttp.go 1.7KB

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