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)
| 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. |
| 37 | func 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 | |
| 58 | func processGitRequest(r *http.Request) (bool, error) { |
| 59 | const infoRefsPath = "/info/refs" |
no test coverage detected
searching dependent graphs…