forked from tangled.org/core
Monorepo for Tangled — https://tangled.org

appview: git: proxy requests consistently

Changed files
+7 -20
appview
state
+7 -20
appview/state/git_http.go
···
if s.config.Core.Dev {
scheme = "http"
}
-
targetURL := fmt.Sprintf("%s://%s/%s/%s/info/refs?%s", scheme, knot, user.DID, repo, r.URL.RawQuery)
-
resp, err := http.Get(targetURL)
-
if err != nil {
-
http.Error(w, err.Error(), http.StatusInternalServerError)
-
return
-
}
-
defer resp.Body.Close()
-
// Copy response headers
-
for k, v := range resp.Header {
-
w.Header()[k] = v
-
}
-
-
// Set response status code
-
w.WriteHeader(resp.StatusCode)
-
-
// Copy response body
-
if _, err := io.Copy(w, resp.Body); err != nil {
-
http.Error(w, err.Error(), http.StatusInternalServerError)
-
return
-
}
+
targetURL := fmt.Sprintf("%s://%s/%s/%s/info/refs?%s", scheme, knot, user.DID, repo, r.URL.RawQuery)
+
s.proxyRequest(w, r, targetURL)
}
···
if s.config.Core.Dev {
scheme = "http"
}
+
targetURL := fmt.Sprintf("%s://%s/%s/%s/git-upload-pack?%s", scheme, knot, user.DID, repo, r.URL.RawQuery)
+
s.proxyRequest(w, r, targetURL)
+
}
+
+
func (s *State) proxyRequest(w http.ResponseWriter, r *http.Request, targetURL string) {
client := &http.Client{}
// Create new request