this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

rainbow: fix getRepo redirects (#1049)

Rainbow was accidentially following HTTP redirects and streaming back
full CAR files when handling getRepo requests.

This correctly passes through the HTTP 3xx response back to the client,
which then does the request to the PDS.

Note that proxying or returning the CAR directly isn't *forbidden*, it
just isn't the behavior we want right now. We might eventually do
proxying and coalescing/caching in rainbow/relay to reduce network load.

authored by

bnewbold and committed by
GitHub
50d91904 093d8191

+19 -3
+8 -2
splitter/handlers.go
··· 72 72 // new context to outlive original HTTP request 73 73 ctx := context.Background() 74 74 xrpcc := xrpc.Client{ 75 - Client: s.upstreamClient, 75 + Client: s.peerClient, 76 76 Host: hostname, 77 77 } 78 78 if err := comatproto.SyncRequestCrawl(ctx, &xrpcc, &body); err != nil { ··· 129 129 } 130 130 defer upstreamResp.Body.Close() 131 131 132 - respWriter.Header()["Content-Type"] = []string{upstreamResp.Header.Get("Content-Type")} 132 + // copy a subset of headers 133 + for _, hdr := range []string{"Content-Type", "Content-Length", "Location"} { 134 + val := upstreamResp.Header.Get(hdr) 135 + if val != "" { 136 + respWriter.Header().Set(hdr, val) 137 + } 138 + } 133 139 respWriter.WriteHeader(upstreamResp.StatusCode) 134 140 135 141 _, err = io.Copy(respWriter, upstreamResp.Body)
+11 -1
splitter/splitter.go
··· 43 43 logger *slog.Logger 44 44 45 45 upstreamClient *http.Client 46 + peerClient *http.Client 46 47 nextCrawlers []*url.URL 47 48 } 48 49 ··· 122 123 return nil, fmt.Errorf("failed to parse upstream url %#v: %w", conf.UpstreamHostHTTP(), err) 123 124 } 124 125 126 + // generic HTTP client for upstream relay and collectiondr; but disable automatic following of redirects 127 + upstreamClient := http.Client{ 128 + Timeout: 10 * time.Second, 129 + CheckRedirect: func(req *http.Request, via []*http.Request) error { 130 + return http.ErrUseLastResponse 131 + }, 132 + } 133 + 125 134 s := &Splitter{ 126 135 conf: conf, 127 136 consumers: make(map[uint64]*SocketConsumer), 128 137 logger: logger, 129 - upstreamClient: util.RobustHTTPClient(), 138 + upstreamClient: &upstreamClient, 139 + peerClient: util.RobustHTTPClient(), 130 140 nextCrawlers: nextCrawlerURLs, 131 141 } 132 142