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.

http.go 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Copyright 2019 The Gitea Authors. All rights reserved.
  3. // SPDX-License-Identifier: MIT
  4. package repo
  5. import (
  6. "bytes"
  7. "compress/gzip"
  8. gocontext "context"
  9. "fmt"
  10. "net/http"
  11. "os"
  12. "path"
  13. "regexp"
  14. "strconv"
  15. "strings"
  16. "sync"
  17. "time"
  18. actions_model "code.gitea.io/gitea/models/actions"
  19. auth_model "code.gitea.io/gitea/models/auth"
  20. "code.gitea.io/gitea/models/perm"
  21. access_model "code.gitea.io/gitea/models/perm/access"
  22. repo_model "code.gitea.io/gitea/models/repo"
  23. "code.gitea.io/gitea/models/unit"
  24. "code.gitea.io/gitea/modules/context"
  25. "code.gitea.io/gitea/modules/git"
  26. "code.gitea.io/gitea/modules/log"
  27. repo_module "code.gitea.io/gitea/modules/repository"
  28. "code.gitea.io/gitea/modules/setting"
  29. "code.gitea.io/gitea/modules/structs"
  30. "code.gitea.io/gitea/modules/util"
  31. repo_service "code.gitea.io/gitea/services/repository"
  32. "github.com/go-chi/cors"
  33. )
  34. func HTTPGitEnabledHandler(ctx *context.Context) {
  35. if setting.Repository.DisableHTTPGit {
  36. ctx.Resp.WriteHeader(http.StatusForbidden)
  37. _, _ = ctx.Resp.Write([]byte("Interacting with repositories by HTTP protocol is not allowed"))
  38. }
  39. }
  40. func CorsHandler() func(next http.Handler) http.Handler {
  41. if setting.Repository.AccessControlAllowOrigin != "" {
  42. return cors.Handler(cors.Options{
  43. AllowedOrigins: []string{setting.Repository.AccessControlAllowOrigin},
  44. AllowedHeaders: []string{"Content-Type", "Authorization", "User-Agent"},
  45. })
  46. }
  47. return func(next http.Handler) http.Handler {
  48. return next
  49. }
  50. }
  51. // httpBase implementation git smart HTTP protocol
  52. func httpBase(ctx *context.Context) (h *serviceHandler) {
  53. username := ctx.Params(":username")
  54. reponame := strings.TrimSuffix(ctx.Params(":reponame"), ".git")
  55. if ctx.FormString("go-get") == "1" {
  56. context.EarlyResponseForGoGetMeta(ctx)
  57. return
  58. }
  59. var isPull, receivePack bool
  60. service := ctx.FormString("service")
  61. if service == "git-receive-pack" ||
  62. strings.HasSuffix(ctx.Req.URL.Path, "git-receive-pack") {
  63. isPull = false
  64. receivePack = true
  65. } else if service == "git-upload-pack" ||
  66. strings.HasSuffix(ctx.Req.URL.Path, "git-upload-pack") {
  67. isPull = true
  68. } else if service == "git-upload-archive" ||
  69. strings.HasSuffix(ctx.Req.URL.Path, "git-upload-archive") {
  70. isPull = true
  71. } else {
  72. isPull = ctx.Req.Method == "GET"
  73. }
  74. var accessMode perm.AccessMode
  75. if isPull {
  76. accessMode = perm.AccessModeRead
  77. } else {
  78. accessMode = perm.AccessModeWrite
  79. }
  80. isWiki := false
  81. unitType := unit.TypeCode
  82. var wikiRepoName string
  83. if strings.HasSuffix(reponame, ".wiki") {
  84. isWiki = true
  85. unitType = unit.TypeWiki
  86. wikiRepoName = reponame
  87. reponame = reponame[:len(reponame)-5]
  88. }
  89. owner := ctx.ContextUser
  90. if !owner.IsOrganization() && !owner.IsActive {
  91. ctx.PlainText(http.StatusForbidden, "Repository cannot be accessed. You cannot push or open issues/pull-requests.")
  92. return
  93. }
  94. repoExist := true
  95. repo, err := repo_model.GetRepositoryByName(owner.ID, reponame)
  96. if err != nil {
  97. if repo_model.IsErrRepoNotExist(err) {
  98. if redirectRepoID, err := repo_model.LookupRedirect(owner.ID, reponame); err == nil {
  99. context.RedirectToRepo(ctx.Base, redirectRepoID)
  100. return
  101. }
  102. repoExist = false
  103. } else {
  104. ctx.ServerError("GetRepositoryByName", err)
  105. return
  106. }
  107. }
  108. // Don't allow pushing if the repo is archived
  109. if repoExist && repo.IsArchived && !isPull {
  110. ctx.PlainText(http.StatusForbidden, "This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.")
  111. return
  112. }
  113. // Only public pull don't need auth.
  114. isPublicPull := repoExist && !repo.IsPrivate && isPull
  115. var (
  116. askAuth = !isPublicPull || setting.Service.RequireSignInView
  117. environ []string
  118. )
  119. // don't allow anonymous pulls if organization is not public
  120. if isPublicPull {
  121. if err := repo.LoadOwner(ctx); err != nil {
  122. ctx.ServerError("LoadOwner", err)
  123. return
  124. }
  125. askAuth = askAuth || (repo.Owner.Visibility != structs.VisibleTypePublic)
  126. }
  127. // check access
  128. if askAuth {
  129. // rely on the results of Contexter
  130. if !ctx.IsSigned {
  131. // TODO: support digit auth - which would be Authorization header with digit
  132. ctx.Resp.Header().Set("WWW-Authenticate", "Basic realm=\".\"")
  133. ctx.Error(http.StatusUnauthorized)
  134. return
  135. }
  136. context.CheckRepoScopedToken(ctx, repo, auth_model.GetScopeLevelFromAccessMode(accessMode))
  137. if ctx.Written() {
  138. return
  139. }
  140. if ctx.IsBasicAuth && ctx.Data["IsApiToken"] != true && ctx.Data["IsActionsToken"] != true {
  141. _, err = auth_model.GetTwoFactorByUID(ctx.Doer.ID)
  142. if err == nil {
  143. // TODO: This response should be changed to "invalid credentials" for security reasons once the expectation behind it (creating an app token to authenticate) is properly documented
  144. ctx.PlainText(http.StatusUnauthorized, "Users with two-factor authentication enabled cannot perform HTTP/HTTPS operations via plain username and password. Please create and use a personal access token on the user settings page")
  145. return
  146. } else if !auth_model.IsErrTwoFactorNotEnrolled(err) {
  147. ctx.ServerError("IsErrTwoFactorNotEnrolled", err)
  148. return
  149. }
  150. }
  151. if !ctx.Doer.IsActive || ctx.Doer.ProhibitLogin {
  152. ctx.PlainText(http.StatusForbidden, "Your account is disabled.")
  153. return
  154. }
  155. environ = []string{
  156. repo_module.EnvRepoUsername + "=" + username,
  157. repo_module.EnvRepoName + "=" + reponame,
  158. repo_module.EnvPusherName + "=" + ctx.Doer.Name,
  159. repo_module.EnvPusherID + fmt.Sprintf("=%d", ctx.Doer.ID),
  160. repo_module.EnvAppURL + "=" + setting.AppURL,
  161. }
  162. if repoExist {
  163. // Because of special ref "refs/for" .. , need delay write permission check
  164. if git.SupportProcReceive {
  165. accessMode = perm.AccessModeRead
  166. }
  167. if ctx.Data["IsActionsToken"] == true {
  168. taskID := ctx.Data["ActionsTaskID"].(int64)
  169. task, err := actions_model.GetTaskByID(ctx, taskID)
  170. if err != nil {
  171. ctx.ServerError("GetTaskByID", err)
  172. return
  173. }
  174. if task.RepoID != repo.ID {
  175. ctx.PlainText(http.StatusForbidden, "User permission denied")
  176. return
  177. }
  178. if task.IsForkPullRequest {
  179. if accessMode > perm.AccessModeRead {
  180. ctx.PlainText(http.StatusForbidden, "User permission denied")
  181. return
  182. }
  183. environ = append(environ, fmt.Sprintf("%s=%d", repo_module.EnvActionPerm, perm.AccessModeRead))
  184. } else {
  185. if accessMode > perm.AccessModeWrite {
  186. ctx.PlainText(http.StatusForbidden, "User permission denied")
  187. return
  188. }
  189. environ = append(environ, fmt.Sprintf("%s=%d", repo_module.EnvActionPerm, perm.AccessModeWrite))
  190. }
  191. } else {
  192. p, err := access_model.GetUserRepoPermission(ctx, repo, ctx.Doer)
  193. if err != nil {
  194. ctx.ServerError("GetUserRepoPermission", err)
  195. return
  196. }
  197. if !p.CanAccess(accessMode, unitType) {
  198. ctx.PlainText(http.StatusNotFound, "Repository not found")
  199. return
  200. }
  201. }
  202. if !isPull && repo.IsMirror {
  203. ctx.PlainText(http.StatusForbidden, "mirror repository is read-only")
  204. return
  205. }
  206. }
  207. if !ctx.Doer.KeepEmailPrivate {
  208. environ = append(environ, repo_module.EnvPusherEmail+"="+ctx.Doer.Email)
  209. }
  210. if isWiki {
  211. environ = append(environ, repo_module.EnvRepoIsWiki+"=true")
  212. } else {
  213. environ = append(environ, repo_module.EnvRepoIsWiki+"=false")
  214. }
  215. }
  216. if !repoExist {
  217. if !receivePack {
  218. ctx.PlainText(http.StatusNotFound, "Repository not found")
  219. return
  220. }
  221. if isWiki { // you cannot send wiki operation before create the repository
  222. ctx.PlainText(http.StatusNotFound, "Repository not found")
  223. return
  224. }
  225. if owner.IsOrganization() && !setting.Repository.EnablePushCreateOrg {
  226. ctx.PlainText(http.StatusForbidden, "Push to create is not enabled for organizations.")
  227. return
  228. }
  229. if !owner.IsOrganization() && !setting.Repository.EnablePushCreateUser {
  230. ctx.PlainText(http.StatusForbidden, "Push to create is not enabled for users.")
  231. return
  232. }
  233. // Return dummy payload if GET receive-pack
  234. if ctx.Req.Method == http.MethodGet {
  235. dummyInfoRefs(ctx)
  236. return
  237. }
  238. repo, err = repo_service.PushCreateRepo(ctx, ctx.Doer, owner, reponame)
  239. if err != nil {
  240. log.Error("pushCreateRepo: %v", err)
  241. ctx.Status(http.StatusNotFound)
  242. return
  243. }
  244. }
  245. if isWiki {
  246. // Ensure the wiki is enabled before we allow access to it
  247. if _, err := repo.GetUnit(ctx, unit.TypeWiki); err != nil {
  248. if repo_model.IsErrUnitTypeNotExist(err) {
  249. ctx.PlainText(http.StatusForbidden, "repository wiki is disabled")
  250. return
  251. }
  252. log.Error("Failed to get the wiki unit in %-v Error: %v", repo, err)
  253. ctx.ServerError("GetUnit(UnitTypeWiki) for "+repo.FullName(), err)
  254. return
  255. }
  256. }
  257. environ = append(environ, repo_module.EnvRepoID+fmt.Sprintf("=%d", repo.ID))
  258. w := ctx.Resp
  259. r := ctx.Req
  260. cfg := &serviceConfig{
  261. UploadPack: true,
  262. ReceivePack: true,
  263. Env: environ,
  264. }
  265. r.URL.Path = strings.ToLower(r.URL.Path) // blue: In case some repo name has upper case name
  266. dir := repo_model.RepoPath(username, reponame)
  267. if isWiki {
  268. dir = repo_model.RepoPath(username, wikiRepoName)
  269. }
  270. return &serviceHandler{cfg, w, r, dir, cfg.Env}
  271. }
  272. var (
  273. infoRefsCache []byte
  274. infoRefsOnce sync.Once
  275. )
  276. func dummyInfoRefs(ctx *context.Context) {
  277. infoRefsOnce.Do(func() {
  278. tmpDir, err := os.MkdirTemp(os.TempDir(), "gitea-info-refs-cache")
  279. if err != nil {
  280. log.Error("Failed to create temp dir for git-receive-pack cache: %v", err)
  281. return
  282. }
  283. defer func() {
  284. if err := util.RemoveAll(tmpDir); err != nil {
  285. log.Error("RemoveAll: %v", err)
  286. }
  287. }()
  288. if err := git.InitRepository(ctx, tmpDir, true); err != nil {
  289. log.Error("Failed to init bare repo for git-receive-pack cache: %v", err)
  290. return
  291. }
  292. refs, _, err := git.NewCommand(ctx, "receive-pack", "--stateless-rpc", "--advertise-refs", ".").RunStdBytes(&git.RunOpts{Dir: tmpDir})
  293. if err != nil {
  294. log.Error(fmt.Sprintf("%v - %s", err, string(refs)))
  295. }
  296. log.Debug("populating infoRefsCache: \n%s", string(refs))
  297. infoRefsCache = refs
  298. })
  299. ctx.RespHeader().Set("Expires", "Fri, 01 Jan 1980 00:00:00 GMT")
  300. ctx.RespHeader().Set("Pragma", "no-cache")
  301. ctx.RespHeader().Set("Cache-Control", "no-cache, max-age=0, must-revalidate")
  302. ctx.RespHeader().Set("Content-Type", "application/x-git-receive-pack-advertisement")
  303. _, _ = ctx.Write(packetWrite("# service=git-receive-pack\n"))
  304. _, _ = ctx.Write([]byte("0000"))
  305. _, _ = ctx.Write(infoRefsCache)
  306. }
  307. type serviceConfig struct {
  308. UploadPack bool
  309. ReceivePack bool
  310. Env []string
  311. }
  312. type serviceHandler struct {
  313. cfg *serviceConfig
  314. w http.ResponseWriter
  315. r *http.Request
  316. dir string
  317. environ []string
  318. }
  319. func (h *serviceHandler) setHeaderNoCache() {
  320. h.w.Header().Set("Expires", "Fri, 01 Jan 1980 00:00:00 GMT")
  321. h.w.Header().Set("Pragma", "no-cache")
  322. h.w.Header().Set("Cache-Control", "no-cache, max-age=0, must-revalidate")
  323. }
  324. func (h *serviceHandler) setHeaderCacheForever() {
  325. now := time.Now().Unix()
  326. expires := now + 31536000
  327. h.w.Header().Set("Date", fmt.Sprintf("%d", now))
  328. h.w.Header().Set("Expires", fmt.Sprintf("%d", expires))
  329. h.w.Header().Set("Cache-Control", "public, max-age=31536000")
  330. }
  331. func containsParentDirectorySeparator(v string) bool {
  332. if !strings.Contains(v, "..") {
  333. return false
  334. }
  335. for _, ent := range strings.FieldsFunc(v, isSlashRune) {
  336. if ent == ".." {
  337. return true
  338. }
  339. }
  340. return false
  341. }
  342. func isSlashRune(r rune) bool { return r == '/' || r == '\\' }
  343. func (h *serviceHandler) sendFile(contentType, file string) {
  344. if containsParentDirectorySeparator(file) {
  345. log.Error("request file path contains invalid path: %v", file)
  346. h.w.WriteHeader(http.StatusBadRequest)
  347. return
  348. }
  349. reqFile := path.Join(h.dir, file)
  350. fi, err := os.Stat(reqFile)
  351. if os.IsNotExist(err) {
  352. h.w.WriteHeader(http.StatusNotFound)
  353. return
  354. }
  355. h.w.Header().Set("Content-Type", contentType)
  356. h.w.Header().Set("Content-Length", fmt.Sprintf("%d", fi.Size()))
  357. h.w.Header().Set("Last-Modified", fi.ModTime().Format(http.TimeFormat))
  358. http.ServeFile(h.w, h.r, reqFile)
  359. }
  360. // one or more key=value pairs separated by colons
  361. var safeGitProtocolHeader = regexp.MustCompile(`^[0-9a-zA-Z]+=[0-9a-zA-Z]+(:[0-9a-zA-Z]+=[0-9a-zA-Z]+)*$`)
  362. func prepareGitCmdWithAllowedService(service string, h *serviceHandler) (*git.Command, error) {
  363. if service == "receive-pack" && h.cfg.ReceivePack {
  364. return git.NewCommand(h.r.Context(), "receive-pack"), nil
  365. }
  366. if service == "upload-pack" && h.cfg.UploadPack {
  367. return git.NewCommand(h.r.Context(), "upload-pack"), nil
  368. }
  369. return nil, fmt.Errorf("service %q is not allowed", service)
  370. }
  371. func serviceRPC(h *serviceHandler, service string) {
  372. defer func() {
  373. if err := h.r.Body.Close(); err != nil {
  374. log.Error("serviceRPC: Close: %v", err)
  375. }
  376. }()
  377. expectedContentType := fmt.Sprintf("application/x-git-%s-request", service)
  378. if h.r.Header.Get("Content-Type") != expectedContentType {
  379. log.Error("Content-Type (%q) doesn't match expected: %q", h.r.Header.Get("Content-Type"), expectedContentType)
  380. h.w.WriteHeader(http.StatusUnauthorized)
  381. return
  382. }
  383. cmd, err := prepareGitCmdWithAllowedService(service, h)
  384. if err != nil {
  385. log.Error("Failed to prepareGitCmdWithService: %v", err)
  386. h.w.WriteHeader(http.StatusUnauthorized)
  387. return
  388. }
  389. h.w.Header().Set("Content-Type", fmt.Sprintf("application/x-git-%s-result", service))
  390. reqBody := h.r.Body
  391. // Handle GZIP.
  392. if h.r.Header.Get("Content-Encoding") == "gzip" {
  393. reqBody, err = gzip.NewReader(reqBody)
  394. if err != nil {
  395. log.Error("Fail to create gzip reader: %v", err)
  396. h.w.WriteHeader(http.StatusInternalServerError)
  397. return
  398. }
  399. }
  400. // set this for allow pre-receive and post-receive execute
  401. h.environ = append(h.environ, "SSH_ORIGINAL_COMMAND="+service)
  402. if protocol := h.r.Header.Get("Git-Protocol"); protocol != "" && safeGitProtocolHeader.MatchString(protocol) {
  403. h.environ = append(h.environ, "GIT_PROTOCOL="+protocol)
  404. }
  405. var stderr bytes.Buffer
  406. cmd.AddArguments("--stateless-rpc").AddDynamicArguments(h.dir)
  407. cmd.SetDescription(fmt.Sprintf("%s %s %s [repo_path: %s]", git.GitExecutable, service, "--stateless-rpc", h.dir))
  408. if err := cmd.Run(&git.RunOpts{
  409. Dir: h.dir,
  410. Env: append(os.Environ(), h.environ...),
  411. Stdout: h.w,
  412. Stdin: reqBody,
  413. Stderr: &stderr,
  414. UseContextTimeout: true,
  415. }); err != nil {
  416. if err.Error() != "signal: killed" {
  417. log.Error("Fail to serve RPC(%s) in %s: %v - %s", service, h.dir, err, stderr.String())
  418. }
  419. return
  420. }
  421. }
  422. // ServiceUploadPack implements Git Smart HTTP protocol
  423. func ServiceUploadPack(ctx *context.Context) {
  424. h := httpBase(ctx)
  425. if h != nil {
  426. serviceRPC(h, "upload-pack")
  427. }
  428. }
  429. // ServiceReceivePack implements Git Smart HTTP protocol
  430. func ServiceReceivePack(ctx *context.Context) {
  431. h := httpBase(ctx)
  432. if h != nil {
  433. serviceRPC(h, "receive-pack")
  434. }
  435. }
  436. func getServiceType(r *http.Request) string {
  437. serviceType := r.FormValue("service")
  438. if !strings.HasPrefix(serviceType, "git-") {
  439. return ""
  440. }
  441. return strings.TrimPrefix(serviceType, "git-")
  442. }
  443. func updateServerInfo(ctx gocontext.Context, dir string) []byte {
  444. out, _, err := git.NewCommand(ctx, "update-server-info").RunStdBytes(&git.RunOpts{Dir: dir})
  445. if err != nil {
  446. log.Error(fmt.Sprintf("%v - %s", err, string(out)))
  447. }
  448. return out
  449. }
  450. func packetWrite(str string) []byte {
  451. s := strconv.FormatInt(int64(len(str)+4), 16)
  452. if len(s)%4 != 0 {
  453. s = strings.Repeat("0", 4-len(s)%4) + s
  454. }
  455. return []byte(s + str)
  456. }
  457. // GetInfoRefs implements Git dumb HTTP
  458. func GetInfoRefs(ctx *context.Context) {
  459. h := httpBase(ctx)
  460. if h == nil {
  461. return
  462. }
  463. h.setHeaderNoCache()
  464. service := getServiceType(h.r)
  465. cmd, err := prepareGitCmdWithAllowedService(service, h)
  466. if err == nil {
  467. if protocol := h.r.Header.Get("Git-Protocol"); protocol != "" && safeGitProtocolHeader.MatchString(protocol) {
  468. h.environ = append(h.environ, "GIT_PROTOCOL="+protocol)
  469. }
  470. h.environ = append(os.Environ(), h.environ...)
  471. refs, _, err := cmd.AddArguments("--stateless-rpc", "--advertise-refs", ".").RunStdBytes(&git.RunOpts{Env: h.environ, Dir: h.dir})
  472. if err != nil {
  473. log.Error(fmt.Sprintf("%v - %s", err, string(refs)))
  474. }
  475. h.w.Header().Set("Content-Type", fmt.Sprintf("application/x-git-%s-advertisement", service))
  476. h.w.WriteHeader(http.StatusOK)
  477. _, _ = h.w.Write(packetWrite("# service=git-" + service + "\n"))
  478. _, _ = h.w.Write([]byte("0000"))
  479. _, _ = h.w.Write(refs)
  480. } else {
  481. updateServerInfo(ctx, h.dir)
  482. h.sendFile("text/plain; charset=utf-8", "info/refs")
  483. }
  484. }
  485. // GetTextFile implements Git dumb HTTP
  486. func GetTextFile(p string) func(*context.Context) {
  487. return func(ctx *context.Context) {
  488. h := httpBase(ctx)
  489. if h != nil {
  490. h.setHeaderNoCache()
  491. file := ctx.Params("file")
  492. if file != "" {
  493. h.sendFile("text/plain", "objects/info/"+file)
  494. } else {
  495. h.sendFile("text/plain", p)
  496. }
  497. }
  498. }
  499. }
  500. // GetInfoPacks implements Git dumb HTTP
  501. func GetInfoPacks(ctx *context.Context) {
  502. h := httpBase(ctx)
  503. if h != nil {
  504. h.setHeaderCacheForever()
  505. h.sendFile("text/plain; charset=utf-8", "objects/info/packs")
  506. }
  507. }
  508. // GetLooseObject implements Git dumb HTTP
  509. func GetLooseObject(ctx *context.Context) {
  510. h := httpBase(ctx)
  511. if h != nil {
  512. h.setHeaderCacheForever()
  513. h.sendFile("application/x-git-loose-object", fmt.Sprintf("objects/%s/%s",
  514. ctx.Params("head"), ctx.Params("hash")))
  515. }
  516. }
  517. // GetPackFile implements Git dumb HTTP
  518. func GetPackFile(ctx *context.Context) {
  519. h := httpBase(ctx)
  520. if h != nil {
  521. h.setHeaderCacheForever()
  522. h.sendFile("application/x-git-packed-objects", "objects/pack/pack-"+ctx.Params("file")+".pack")
  523. }
  524. }
  525. // GetIdxFile implements Git dumb HTTP
  526. func GetIdxFile(ctx *context.Context) {
  527. h := httpBase(ctx)
  528. if h != nil {
  529. h.setHeaderCacheForever()
  530. h.sendFile("application/x-git-packed-objects-toc", "objects/pack/pack-"+ctx.Params("file")+".idx")
  531. }
  532. }