8c181bc662746a9d34dc68ff87a9be1865e9aa2e

Author
Ayman Bagabas <ayman.bagabas@gmail.com>
Committer
Ayman Bagabas <ayman.bagabas@gmail.com>
Date

Message

fix(web): write http prefix before references

Diff

 1diff --git a/pkg/web/git.go b/pkg/web/git.go
 2index 8f1170bce71edda69e81f171415776b4800b1474..9778a1a5406c01d5bdfb1e156c300bffea84a6dd 100644
 3--- a/pkg/web/git.go
 4+++ b/pkg/web/git.go
 5@@ -10,6 +10,7 @@ import (
 6 	"net/http"
 7 	"os"
 8 	"path/filepath"
 9+	"strconv"
10 	"strings"
11 	"time"
12 
13@@ -485,7 +486,7 @@ func getInfoRefs(w http.ResponseWriter, r *http.Request) {
14 	cfg := config.FromContext(ctx)
15 	dir, repoName, file := mux.Vars(r)["dir"], mux.Vars(r)["repo"], mux.Vars(r)["file"]
16 	service := getServiceType(r)
17-	version := r.Header.Get("Git-Protocol")
18+	protocol := r.Header.Get("Git-Protocol")
19 
20 	gitHttpUploadCounter.WithLabelValues(repoName, file).Inc()
21 
22@@ -510,8 +511,21 @@ func getInfoRefs(w http.ResponseWriter, r *http.Request) {
23 				"SOFT_SERVE_USERNAME=" + user.Username(),
24 			}...)
25 		}
26-		if len(version) != 0 {
27-			cmd.Env = append(cmd.Env, fmt.Sprintf("GIT_PROTOCOL=%s", version))
28+		if len(protocol) != 0 {
29+			cmd.Env = append(cmd.Env, fmt.Sprintf("GIT_PROTOCOL=%s", protocol))
30+		}
31+
32+		var version int
33+		for _, p := range strings.Split(protocol, ":") {
34+			if strings.HasPrefix(p, "version=") {
35+				if v, _ := strconv.Atoi(p[8:]); v > version {
36+					version = v
37+				}
38+			}
39+		}
40+
41+		if version < 2 {
42+			git.WritePktline(w, "# service="+service.String()) // nolint: errcheck
43 		}
44 
45 		if err := service.Handler(ctx, cmd); err != nil {
46@@ -522,10 +536,6 @@ func getInfoRefs(w http.ResponseWriter, r *http.Request) {
47 		hdrNocache(w)
48 		w.Header().Set("Content-Type", fmt.Sprintf("application/x-%s-advertisement", service))
49 		w.WriteHeader(http.StatusOK)
50-		if len(version) == 0 {
51-			git.WritePktline(w, "# service="+service.String()) // nolint: errcheck
52-		}
53-
54 		w.Write(refs.Bytes()) // nolint: errcheck
55 	} else {
56 		// Dumb HTTP