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 if s.config.Core.Dev { 19 scheme = "http" 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 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 - } 42 43 } 44 ··· 55 if s.config.Core.Dev { 56 scheme = "http" 57 } 58 targetURL := fmt.Sprintf("%s://%s/%s/%s/git-upload-pack?%s", scheme, knot, user.DID, repo, r.URL.RawQuery) 59 client := &http.Client{} 60 61 // Create new request
··· 18 if s.config.Core.Dev { 19 scheme = "http" 20 } 21 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) 24 25 } 26 ··· 37 if s.config.Core.Dev { 38 scheme = "http" 39 } 40 + 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) { 46 client := &http.Client{} 47 48 // Create new request