From 0e61aa4e3941eb751b3789d257d25d8cc03ae101 Mon Sep 17 00:00:00 2001 From: Simone Gotti Date: Mon, 9 Sep 2019 15:40:30 +0200 Subject: [PATCH] gitserver: don't return http response/error when calling external git process On a git process error don't write the error message to the response body since it'll break the git protocol and don't try to write the status header (since it's not possible as it was automatically written by the go http server before writing the body). --- internal/git-handler/handler.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/internal/git-handler/handler.go b/internal/git-handler/handler.go index 751d2bb..e25398d 100644 --- a/internal/git-handler/handler.go +++ b/internal/git-handler/handler.go @@ -207,7 +207,8 @@ func (h *GitSmartHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } res, err := InfoRefsResponse(ctx, repoAbsPath, serviceName) if err != nil { - http.Error(w, err.Error(), http.StatusBadRequest) + // we cannot return any http error since the http header has already been written + h.log.Errorf("git command error: %v", err) return } @@ -218,7 +219,6 @@ func (h *GitSmartHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/x-git-upload-pack-result") if err := gitService(ctx, w, body, repoAbsPath, "upload-pack"); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) // we cannot return any http error since the http header has already been written h.log.Errorf("git command error: %v", err) } @@ -226,7 +226,6 @@ func (h *GitSmartHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/x-git-receive-pack-result") if err := gitService(ctx, w, body, repoAbsPath, "receive-pack"); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) // we cannot return any http error since the http header has already been written h.log.Errorf("git command error: %v", err) }