MCPcopy
hub / github.com/harness/harness / GitPathBefore

Function GitPathBefore

app/api/middleware/encode/encode.go:37–56  ·  view source on GitHub ↗

GitPathBefore wraps an http.HandlerFunc in a layer that encodes a path coming as part of the GIT api (e.g. "space1/repo.git") before executing the provided http.HandlerFunc.

(next http.Handler)

Source from the content-addressed store, hash-verified

35// GitPathBefore wraps an http.HandlerFunc in a layer that encodes a path coming
36// as part of the GIT api (e.g. "space1/repo.git") before executing the provided http.HandlerFunc.
37func GitPathBefore(next http.Handler) http.Handler {
38 return http.HandlerFunc(
39 func(w http.ResponseWriter, r *http.Request) {
40 ctx := r.Context()
41 ok, err := pathTerminatedWithMarker(r, "", ".git", "")
42 if err != nil {
43 render.TranslatedUserError(ctx, w, err)
44 return
45 }
46 if !ok {
47 if _, err = processGitRequest(r); err != nil {
48 render.TranslatedUserError(ctx, w, err)
49 return
50 }
51 }
52
53 next.ServeHTTP(w, r)
54 },
55 )
56}
57
58func processGitRequest(r *http.Request) (bool, error) {
59 const infoRefsPath = "/info/refs"

Callers 1

NewGitHandlerFunction · 0.92

Calls 4

TranslatedUserErrorFunction · 0.92
pathTerminatedWithMarkerFunction · 0.85
processGitRequestFunction · 0.85
ServeHTTPMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…