Mirror of @tangled.org/core. Running on a Raspberry Pi Zero 2

appview: git: proxy requests consistently

authored by tjh.dev and committed by

Tangled d5051d79 1a455273

+7 -20
+7 -20
appview/state/git_http.go
··· 18 18 if s.config.Core.Dev { 19 19 scheme = "http" 20 20 } 21 + 21 22 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 - } 23 + s.proxyRequest(w, r, targetURL) 42 24 43 25 } 44 26 ··· 37 55 if s.config.Core.Dev { 38 56 scheme = "http" 39 57 } 58 + 40 59 targetURL := fmt.Sprintf("%s://%s/%s/%s/git-upload-pack?%s", scheme, knot, user.DID, repo, r.URL.RawQuery) 60 + s.proxyRequest(w, r, targetURL) 61 + } 62 + 63 + func (s *State) proxyRequest(w http.ResponseWriter, r *http.Request, targetURL string) { 41 64 client := &http.Client{} 42 65 43 66 // Create new request