From fd838b8d5becb1978dc51106996c80f8cfafb0cb Mon Sep 17 00:00:00 2001 From: bryan newbold Date: Thu, 1 May 2025 14:39:43 -0700 Subject: [PATCH] wire up existing http.Client for sibling requests --- cmd/relay/forward.go | 8 +------- cmd/relay/service.go | 13 +++++++------ 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/cmd/relay/forward.go b/cmd/relay/forward.go index 374325cf..f917826e 100644 --- a/cmd/relay/forward.go +++ b/cmd/relay/forward.go @@ -5,7 +5,6 @@ import ( "io" "net/http" "strings" - "time" "github.com/bluesky-social/indigo/cmd/relay/relay" @@ -36,11 +35,6 @@ func (s *Service) ForwardSiblingRequest(c echo.Context, body []byte) { } } - // TODO: could turn this in to a shared/persistent client - client := http.Client{ - Timeout: 10 * time.Second, - } - for _, rawHost := range s.config.SiblingRelayHosts { hostname, noSSL, err := relay.ParseHostname(rawHost) if err != nil { @@ -75,7 +69,7 @@ func (s *Service) ForwardSiblingRequest(c echo.Context, body []byte) { // add Via header (critical to prevent forwarding loops) upstreamReq.Header.Add("Via", req.Proto+" atproto-relay") - upstreamResp, err := client.Do(upstreamReq) + upstreamResp, err := s.siblingClient.Do(upstreamReq) if err != nil { s.logger.Warn("forwarded admin HTTP request failed", "method", req.Method, "sibling", hostname, "url", u.String(), "err", err) continue diff --git a/cmd/relay/service.go b/cmd/relay/service.go index a5f94414..025e6bf7 100644 --- a/cmd/relay/service.go +++ b/cmd/relay/service.go @@ -23,7 +23,7 @@ type Service struct { relay *relay.Relay config ServiceConfig - crawlForwardClient http.Client + siblingClient http.Client } type ServiceConfig struct { @@ -56,12 +56,13 @@ func NewService(r *relay.Relay, config *ServiceConfig) (*Service, error) { } svc := &Service{ - logger: slog.Default().With("system", "relay"), - relay: r, - config: *config, - crawlForwardClient: http.Client{}, + logger: slog.Default().With("system", "relay"), + relay: r, + config: *config, + siblingClient: http.Client{ + Timeout: 10 * time.Second, + }, } - svc.crawlForwardClient.Timeout = time.Second * 5 return svc, nil } -- 2.51.2