git-handler: handle client requests with gzip Content Encoding
This commit is contained in:
parent
5a74ebf9d8
commit
5876c54837
|
@ -16,6 +16,7 @@ package githandler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"compress/gzip"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
@ -173,6 +174,14 @@ func (h *GitSmartHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
git := &util.Git{GitDir: repoAbsPath}
|
git := &util.Git{GitDir: repoAbsPath}
|
||||||
|
|
||||||
|
body := r.Body
|
||||||
|
if r.Header.Get("Content-Encoding") == "gzip" {
|
||||||
|
body, err = gzip.NewReader(r.Body)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch reqType {
|
switch reqType {
|
||||||
case RequestTypeInfoRefs:
|
case RequestTypeInfoRefs:
|
||||||
if h.createRepo && !exists {
|
if h.createRepo && !exists {
|
||||||
|
@ -206,7 +215,7 @@ func (h *GitSmartHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
case RequestTypeUploadPack:
|
case RequestTypeUploadPack:
|
||||||
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, r.Body, repoAbsPath, "upload-pack"); err != nil {
|
if err := gitService(ctx, w, body, repoAbsPath, "upload-pack"); err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
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.Infof("git command error: %v", err)
|
h.log.Infof("git command error: %v", err)
|
||||||
|
@ -214,7 +223,7 @@ func (h *GitSmartHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
case RequestTypeReceivePack:
|
case RequestTypeReceivePack:
|
||||||
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, r.Body, repoAbsPath, "receive-pack"); err != nil {
|
if err := gitService(ctx, w, body, repoAbsPath, "receive-pack"); err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
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.Infof("git command error: %v", err)
|
h.log.Infof("git command error: %v", err)
|
||||||
|
|
Loading…
Reference in New Issue