Skip to content

Commit

Permalink
fix(web): write http prefix before references
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Apr 30, 2024
1 parent 87d61a3 commit 8c181bc
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions pkg/web/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"net/http"
"os"
"path/filepath"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -485,7 +486,7 @@ func getInfoRefs(w http.ResponseWriter, r *http.Request) {
cfg := config.FromContext(ctx)
dir, repoName, file := mux.Vars(r)["dir"], mux.Vars(r)["repo"], mux.Vars(r)["file"]
service := getServiceType(r)
version := r.Header.Get("Git-Protocol")
protocol := r.Header.Get("Git-Protocol")

gitHttpUploadCounter.WithLabelValues(repoName, file).Inc()

Expand All @@ -510,8 +511,21 @@ func getInfoRefs(w http.ResponseWriter, r *http.Request) {
"SOFT_SERVE_USERNAME=" + user.Username(),
}...)
}
if len(version) != 0 {
cmd.Env = append(cmd.Env, fmt.Sprintf("GIT_PROTOCOL=%s", version))
if len(protocol) != 0 {
cmd.Env = append(cmd.Env, fmt.Sprintf("GIT_PROTOCOL=%s", protocol))
}

var version int
for _, p := range strings.Split(protocol, ":") {
if strings.HasPrefix(p, "version=") {
if v, _ := strconv.Atoi(p[8:]); v > version {
version = v
}
}
}

if version < 2 {
git.WritePktline(w, "# service="+service.String()) // nolint: errcheck
}

if err := service.Handler(ctx, cmd); err != nil {
Expand All @@ -522,10 +536,6 @@ func getInfoRefs(w http.ResponseWriter, r *http.Request) {
hdrNocache(w)
w.Header().Set("Content-Type", fmt.Sprintf("application/x-%s-advertisement", service))
w.WriteHeader(http.StatusOK)
if len(version) == 0 {
git.WritePktline(w, "# service="+service.String()) // nolint: errcheck
}

w.Write(refs.Bytes()) // nolint: errcheck
} else {
// Dumb HTTP
Expand Down

0 comments on commit 8c181bc

Please sign in to comment.