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).
This commit is contained in:
Simone Gotti 2019-09-09 15:40:30 +02:00
parent 6ca985c641
commit 0e61aa4e39
1 changed files with 2 additions and 3 deletions

View File

@ -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)
}