File: upload-pack.go

package info (click to toggle)
gitlab-workhorse 7.6.0%2Bdebian-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 7,440 kB
  • sloc: makefile: 233; sh: 161; python: 15
file content (46 lines) | stat: -rw-r--r-- 1,442 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package git

import (
	"context"
	"fmt"
	"io"
	"net/http"

	"gitlab.com/gitlab-org/gitlab-workhorse/internal/api"
	"gitlab.com/gitlab-org/gitlab-workhorse/internal/gitaly"
	"gitlab.com/gitlab-org/gitlab-workhorse/internal/helper"
)

// Will not return a non-nil error after the response body has been
// written to.
func handleUploadPack(w *HttpResponseWriter, r *http.Request, a *api.Response) error {
	// The body will consist almost entirely of 'have XXX' and 'want XXX'
	// lines; these are about 50 bytes long. With a limit of 10MB the client
	// can send over 200,000 have/want lines.
	buffer, err := helper.ReadAllTempfile(io.LimitReader(r.Body, 10*1024*1024))
	if err != nil {
		return fmt.Errorf("ReadAllTempfile: %v", err)
	}
	defer buffer.Close()
	r.Body.Close()

	action := getService(r)
	writePostRPCHeader(w, action)

	gitProtocol := r.Header.Get("Git-Protocol")

	return handleUploadPackWithGitaly(r.Context(), a, buffer, w, gitProtocol)
}

func handleUploadPackWithGitaly(ctx context.Context, a *api.Response, clientRequest io.Reader, clientResponse io.Writer, gitProtocol string) error {
	smarthttp, err := gitaly.NewSmartHTTPClient(a.GitalyServer)
	if err != nil {
		return fmt.Errorf("smarthttp.UploadPack: %v", err)
	}

	if err := smarthttp.UploadPack(ctx, &a.Repository, clientRequest, clientResponse, gitConfigOptions(a), gitProtocol); err != nil {
		return fmt.Errorf("smarthttp.UploadPack: %v", err)
	}

	return nil
}