this repo has no description
0
fork

Configure Feed

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

automod: re-use HTTP client for PDS blob fetches (#566)

authored by

bnewbold and committed by
GitHub
c72ce234 e7a656b3

+12 -4
+7 -4
automod/engine/blobs.go
··· 9 9 10 10 appbsky "github.com/bluesky-social/indigo/api/bsky" 11 11 lexutil "github.com/bluesky-social/indigo/lex/util" 12 - "github.com/bluesky-social/indigo/util" 13 12 14 13 "github.com/carlmjohnson/versioninfo" 15 14 ) ··· 103 102 104 103 var blobBytes []byte 105 104 106 - // TODO: better way to do this, eg a shared client? 107 - client := util.RobustHTTPClient() 105 + // TODO: potential security issue here with malformed or "localhost" PDS endpoint 108 106 pdsEndpoint := c.Account.Identity.PDSEndpoint() 109 107 xrpcURL := fmt.Sprintf("%s/xrpc/com.atproto.sync.getBlob?did=%s&cid=%s", pdsEndpoint, c.Account.Identity.DID, blob.Ref) 110 108 ··· 114 112 } 115 113 116 114 req.Header.Set("User-Agent", "indigo-automod/"+versioninfo.Short()) 117 - // TODO: more robust PDS hostname check 115 + // TODO: more robust PDS hostname check (eg, future trailing slash or partial path) 118 116 if c.engine.BskyClient.Headers != nil && strings.HasSuffix(pdsEndpoint, ".bsky.network") { 119 117 val, ok := c.engine.BskyClient.Headers["x-ratelimit-bypass"] 120 118 if ok { 121 119 req.Header.Set("x-ratelimit-bypass", val) 122 120 } 121 + } 122 + 123 + client := c.engine.BlobClient 124 + if client == nil { 125 + client = http.DefaultClient 123 126 } 124 127 125 128 resp, err := client.Do(req)
+3
automod/engine/engine.go
··· 4 4 "context" 5 5 "fmt" 6 6 "log/slog" 7 + "net/http" 7 8 "time" 8 9 9 10 "github.com/bluesky-social/indigo/atproto/identity" ··· 38 39 BskyClient *xrpc.Client 39 40 // used to persist moderation actions in mod service (optional) 40 41 AdminClient *xrpc.Client 42 + // used to fetch blobs from upstream PDS instances 43 + BlobClient *http.Client 41 44 } 42 45 43 46 // Entrypoint for external code pushing arbitrary identity events in to the engine.
+2
cmd/hepa/server.go
··· 188 188 bskyClient.Headers = make(map[string]string) 189 189 bskyClient.Headers["x-ratelimit-bypass"] = config.RatelimitBypass 190 190 } 191 + blobClient := util.RobustHTTPClient() 191 192 engine := automod.Engine{ 192 193 Logger: logger, 193 194 Directory: dir, ··· 199 200 Notifier: notifier, 200 201 AdminClient: xrpcc, 201 202 BskyClient: &bskyClient, 203 + BlobClient: blobClient, 202 204 } 203 205 204 206 s := &Server{