forked from tangled.org/core
Monorepo for Tangled

appview: git: proxy requests consistently

authored by tjh.dev and committed by Tangled d5051d79 1a455273

Changed files
+7 -20
appview
state
+7 -20
appview/state/git_http.go
··· 18 18 if s.config.Core.Dev { 19 19 scheme = "http" 20 20 } 21 - targetURL := fmt.Sprintf("%s://%s/%s/%s/info/refs?%s", scheme, knot, user.DID, repo, r.URL.RawQuery) 22 - resp, err := http.Get(targetURL) 23 - if err != nil { 24 - http.Error(w, err.Error(), http.StatusInternalServerError) 25 - return 26 - } 27 - defer resp.Body.Close() 28 21 29 - // Copy response headers 30 - for k, v := range resp.Header { 31 - w.Header()[k] = v 32 - } 33 - 34 - // Set response status code 35 - w.WriteHeader(resp.StatusCode) 36 - 37 - // Copy response body 38 - if _, err := io.Copy(w, resp.Body); err != nil { 39 - http.Error(w, err.Error(), http.StatusInternalServerError) 40 - return 41 - } 22 + targetURL := fmt.Sprintf("%s://%s/%s/%s/info/refs?%s", scheme, knot, user.DID, repo, r.URL.RawQuery) 23 + s.proxyRequest(w, r, targetURL) 42 24 43 25 } 44 26 ··· 55 37 if s.config.Core.Dev { 56 38 scheme = "http" 57 39 } 40 + 58 41 targetURL := fmt.Sprintf("%s://%s/%s/%s/git-upload-pack?%s", scheme, knot, user.DID, repo, r.URL.RawQuery) 42 + s.proxyRequest(w, r, targetURL) 43 + } 44 + 45 + func (s *State) proxyRequest(w http.ResponseWriter, r *http.Request, targetURL string) { 59 46 client := &http.Client{} 60 47 61 48 // Create new request