diff --git a/githttpxfer/githttpxfer.go b/githttpxfer/githttpxfer.go index d2d0a8e..5ab1647 100644 --- a/githttpxfer/githttpxfer.go +++ b/githttpxfer/githttpxfer.go @@ -8,6 +8,7 @@ import ( "os" "regexp" "strings" + "sync" ) var ( @@ -275,7 +276,9 @@ func (ghx *GitHTTPXfer) serviceRPC(ctx Context, rpc string) { return } - if _, err := io.Copy(stdin, body); err != nil { + bufIn := bufPool.Get().([]byte) + defer bufPool.Put(bufIn) + if _, err := io.CopyBuffer(stdin, body, bufIn); err != nil { ghx.logger.Error("failed to write the request body to standard input. ", err.Error()) RenderInternalServerError(res.Writer) return @@ -287,17 +290,24 @@ func (ghx *GitHTTPXfer) serviceRPC(ctx Context, rpc string) { res.SetContentType(fmt.Sprintf("application/x-git-%s-result", rpc)) res.WriteHeader(http.StatusOK) - if _, err := io.Copy(res.Writer, stdout); err != nil { + bufOut := bufPool.Get().([]byte) + defer bufPool.Put(bufOut) + if _, err := io.CopyBuffer(res.Writer, stdout, bufOut); err != nil { ghx.logger.Error("failed to write the standard output to response. ", err.Error()) return } - if err = cmd.Wait(); err != nil { ghx.logger.Error("specified command fails to run or doesn't complete successfully. ", err.Error()) } } +var bufPool = sync.Pool{ + New: func() interface{} { + return make([]byte, 32*1024) + }, +} + func (ghx *GitHTTPXfer) getInfoRefs(ctx Context) { res, req, repoPath := ctx.Response(), ctx.Request(), ctx.RepoPath()