Merge pull request #103 from sgotti/gitserver_dont_write_on_error

gitserver: don't return http response/error when calling external git process
This commit is contained in:
Simone Gotti 2019-09-09 16:43:40 +02:00 committed by GitHub
commit 33c860e78c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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) res, err := InfoRefsResponse(ctx, repoAbsPath, serviceName)
if err != nil { 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 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") w.Header().Set("Content-Type", "application/x-git-upload-pack-result")
if err := gitService(ctx, w, body, repoAbsPath, "upload-pack"); err != nil { 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 // we cannot return any http error since the http header has already been written
h.log.Errorf("git command error: %v", err) 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") w.Header().Set("Content-Type", "application/x-git-receive-pack-result")
if err := gitService(ctx, w, body, repoAbsPath, "receive-pack"); err != nil { 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 // we cannot return any http error since the http header has already been written
h.log.Errorf("git command error: %v", err) h.log.Errorf("git command error: %v", err)
} }