A vibe coded tangled fork which supports pijul.
at d5051d7972983b73dec623360122acb15459354d 79 lines 1.9 kB view raw
1package state 2 3import ( 4 "fmt" 5 "io" 6 "net/http" 7 8 "github.com/bluesky-social/indigo/atproto/identity" 9 "github.com/go-chi/chi/v5" 10) 11 12func (s *State) InfoRefs(w http.ResponseWriter, r *http.Request) { 13 user := r.Context().Value("resolvedId").(identity.Identity) 14 knot := r.Context().Value("knot").(string) 15 repo := chi.URLParam(r, "repo") 16 17 scheme := "https" 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 27func (s *State) UploadPack(w http.ResponseWriter, r *http.Request) { 28 user, ok := r.Context().Value("resolvedId").(identity.Identity) 29 if !ok { 30 http.Error(w, "failed to resolve user", http.StatusInternalServerError) 31 return 32 } 33 knot := r.Context().Value("knot").(string) 34 repo := chi.URLParam(r, "repo") 35 36 scheme := "https" 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 45func (s *State) proxyRequest(w http.ResponseWriter, r *http.Request, targetURL string) { 46 client := &http.Client{} 47 48 // Create new request 49 proxyReq, err := http.NewRequest(r.Method, targetURL, r.Body) 50 if err != nil { 51 http.Error(w, err.Error(), http.StatusInternalServerError) 52 return 53 } 54 55 // Copy original headers 56 proxyReq.Header = r.Header 57 58 // Execute request 59 resp, err := client.Do(proxyReq) 60 if err != nil { 61 http.Error(w, err.Error(), http.StatusInternalServerError) 62 return 63 } 64 defer resp.Body.Close() 65 66 // Copy response headers 67 for k, v := range resp.Header { 68 w.Header()[k] = v 69 } 70 71 // Set response status code 72 w.WriteHeader(resp.StatusCode) 73 74 // Copy response body 75 if _, err := io.Copy(w, resp.Body); err != nil { 76 http.Error(w, err.Error(), http.StatusInternalServerError) 77 return 78 } 79}