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 18KB

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