diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 14:59:07 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 14:59:07 +0300 |
commit | 8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca (patch) | |
tree | 544930fb309b30317ae9797a9683768705d664c4 /workhorse/internal/git/upload-pack.go | |
parent | 4b1de649d0168371549608993deac953eb692019 (diff) |
Add latest changes from gitlab-org/gitlab@13-7-stable-eev13.7.0-rc42
Diffstat (limited to 'workhorse/internal/git/upload-pack.go')
-rw-r--r-- | workhorse/internal/git/upload-pack.go | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/workhorse/internal/git/upload-pack.go b/workhorse/internal/git/upload-pack.go new file mode 100644 index 00000000000..a3dbf2f2e02 --- /dev/null +++ b/workhorse/internal/git/upload-pack.go @@ -0,0 +1,57 @@ +package git + +import ( + "context" + "fmt" + "io" + "net/http" + "time" + + "gitlab.com/gitlab-org/gitlab-workhorse/internal/api" + "gitlab.com/gitlab-org/gitlab-workhorse/internal/gitaly" + "gitlab.com/gitlab-org/gitlab-workhorse/internal/helper" +) + +var ( + uploadPackTimeout = 10 * time.Minute +) + +// 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 { + ctx := r.Context() + + // Prevent the client from holding the connection open indefinitely. A + // transfer rate of 17KiB/sec is sufficient to send 10MiB of data in + // ten minutes, which seems adequate. Most requests will be much smaller. + // This mitigates a use-after-check issue. + // + // We can't reliably interrupt the read from a http handler, but we can + // ensure the request will (eventually) fail: https://github.com/golang/go/issues/16100 + readerCtx, cancel := context.WithTimeout(ctx, uploadPackTimeout) + defer cancel() + + limited := helper.NewContextReader(readerCtx, r.Body) + cr, cw := helper.NewWriteAfterReader(limited, w) + defer cw.Flush() + + action := getService(r) + writePostRPCHeader(w, action) + + gitProtocol := r.Header.Get("Git-Protocol") + + return handleUploadPackWithGitaly(ctx, a, cr, cw, gitProtocol) +} + +func handleUploadPackWithGitaly(ctx context.Context, a *api.Response, clientRequest io.Reader, clientResponse io.Writer, gitProtocol string) error { + ctx, smarthttp, err := gitaly.NewSmartHTTPClient(ctx, 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 +} |