aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorLibravatar Rutger Broekhoff2023-12-29 23:31:42 +0100
committerLibravatar Rutger Broekhoff2023-12-29 23:31:42 +0100
commitfb36a7eb5c3b12f110123e93c29bf9dcca305acf (patch)
tree6731240f57e163cade91c1113f86e54f267222e2 /cmd
parentfe3e8c4d02c3ab9528a10b93c3f401f938895a30 (diff)
downloadgitolfs3-fb36a7eb5c3b12f110123e93c29bf9dcca305acf.tar.gz
gitolfs3-fb36a7eb5c3b12f110123e93c29bf9dcca305acf.zip
Submatch
Diffstat (limited to 'cmd')
-rw-r--r--cmd/git-lfs-server/main.go12
1 files changed, 7 insertions, 5 deletions
diff --git a/cmd/git-lfs-server/main.go b/cmd/git-lfs-server/main.go
index f59269e..19a0747 100644
--- a/cmd/git-lfs-server/main.go
+++ b/cmd/git-lfs-server/main.go
@@ -97,8 +97,6 @@ type batchResponse struct {
97 HashAlgo hashAlgo `json:"hash_algo,omitempty"` 97 HashAlgo hashAlgo `json:"hash_algo,omitempty"`
98} 98}
99 99
100var re = regexp.MustCompile(`^([a-zA-Z0-9-_/]+)\.git/info/lfs/objects/batch$`)
101
102type handler struct { 100type handler struct {
103 mc *minio.Client 101 mc *minio.Client
104 bucket string 102 bucket string
@@ -202,18 +200,22 @@ func isLFSMediaType(t string) bool {
202 return false 200 return false
203} 201}
204 202
203var re = regexp.MustCompile(`^([a-zA-Z0-9-_/]+)\.git/info/lfs/objects/batch$`)
204
205func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { 205func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
206 reqPath := os.Getenv("PATH_INFO") 206 reqPath := os.Getenv("PATH_INFO")
207 if reqPath == "" { 207 if reqPath == "" {
208 reqPath = r.URL.Path 208 reqPath = r.URL.Path
209 } 209 }
210 reqPath = strings.TrimPrefix("/", path.Clean(reqPath))
210 submatches := re.FindStringSubmatch(reqPath) 211 submatches := re.FindStringSubmatch(reqPath)
211 if len(submatches) != 1 { 212 if len(submatches) != 2 {
212 log("Got URL: %s", r.URL.Path) 213 log("Got path: %s, did not match regex", reqPath)
213 makeRespError(w, "Not found", http.StatusNotFound) 214 makeRespError(w, "Not found", http.StatusNotFound)
214 return 215 return
215 } 216 }
216 repo := strings.TrimPrefix("/", path.Clean(submatches[0])) 217 repo := strings.TrimPrefix("/", path.Clean(submatches[1]))
218 log("Repository: %s", repo)
217 219
218 if !slices.ContainsFunc(r.Header.Values("Accept"), isLFSMediaType) { 220 if !slices.ContainsFunc(r.Header.Values("Accept"), isLFSMediaType) {
219 makeRespError(w, "Expected "+lfsMIME+" (with UTF-8 charset) in list of acceptable response media types", http.StatusNotAcceptable) 221 makeRespError(w, "Expected "+lfsMIME+" (with UTF-8 charset) in list of acceptable response media types", http.StatusNotAcceptable)