From c5ae88c51bc29b05a5a95787fe7a0bcb39414aed Mon Sep 17 00:00:00 2001 From: Daniele Sluijters Date: Sat, 26 Nov 2022 21:19:42 +0100 Subject: [PATCH] [chore] Set User-Agent header in transport (#1154) Currently requests set their own User-Agent. This moves it down to set it in the transport's do() method, to guarantee it's always set on all requests. --- internal/transport/deliver.go | 1 - internal/transport/dereference.go | 1 - internal/transport/derefinstance.go | 3 --- internal/transport/derefmedia.go | 1 - internal/transport/finger.go | 1 - internal/transport/transport.go | 2 ++ 6 files changed, 2 insertions(+), 7 deletions(-) diff --git a/internal/transport/deliver.go b/internal/transport/deliver.go index 16ebbd4b6..258fcb6c4 100644 --- a/internal/transport/deliver.go +++ b/internal/transport/deliver.go @@ -82,7 +82,6 @@ func (t *transport) Deliver(ctx context.Context, b []byte, to *url.URL) error { req.Header.Add("Content-Type", string(api.AppActivityLDJSON)) req.Header.Add("Accept-Charset", "utf-8") - req.Header.Add("User-Agent", t.controller.userAgent) req.Header.Set("Host", to.Host) resp, err := t.POST(req, b) diff --git a/internal/transport/dereference.go b/internal/transport/dereference.go index 0c6918550..589bb2f0b 100644 --- a/internal/transport/dereference.go +++ b/internal/transport/dereference.go @@ -63,7 +63,6 @@ func (t *transport) Dereference(ctx context.Context, iri *url.URL) ([]byte, erro req.Header.Add("Accept", string(api.AppActivityLDJSON)+","+string(api.AppActivityJSON)) req.Header.Add("Accept-Charset", "utf-8") - req.Header.Add("User-Agent", t.controller.userAgent) req.Header.Set("Host", iri.Host) // Perform the HTTP request diff --git a/internal/transport/derefinstance.go b/internal/transport/derefinstance.go index 26f5fd02d..5dd108f54 100644 --- a/internal/transport/derefinstance.go +++ b/internal/transport/derefinstance.go @@ -93,7 +93,6 @@ func dereferenceByAPIV1Instance(ctx context.Context, t *transport, iri *url.URL) } req.Header.Add("Accept", string(api.AppJSON)) - req.Header.Add("User-Agent", t.controller.userAgent) req.Header.Set("Host", cleanIRI.Host) resp, err := t.GET(req) @@ -244,7 +243,6 @@ func callNodeInfoWellKnown(ctx context.Context, t *transport, iri *url.URL) (*ur return nil, err } req.Header.Add("Accept", string(api.AppJSON)) - req.Header.Add("User-Agent", t.controller.userAgent) req.Header.Set("Host", cleanIRI.Host) resp, err := t.GET(req) @@ -296,7 +294,6 @@ func callNodeInfo(ctx context.Context, t *transport, iri *url.URL) (*apimodel.No return nil, err } req.Header.Add("Accept", string(api.AppJSON)) - req.Header.Add("User-Agent", t.controller.userAgent) req.Header.Set("Host", iri.Host) resp, err := t.GET(req) diff --git a/internal/transport/derefmedia.go b/internal/transport/derefmedia.go index 14c054cdf..d39db03c8 100644 --- a/internal/transport/derefmedia.go +++ b/internal/transport/derefmedia.go @@ -36,7 +36,6 @@ func (t *transport) DereferenceMedia(ctx context.Context, iri *url.URL) (io.Read return nil, 0, err } req.Header.Add("Accept", "*/*") // we don't know what kind of media we're going to get here - req.Header.Add("User-Agent", t.controller.userAgent) req.Header.Set("Host", iri.Host) // Perform the HTTP request diff --git a/internal/transport/finger.go b/internal/transport/finger.go index cefe93fc9..5523e479d 100644 --- a/internal/transport/finger.go +++ b/internal/transport/finger.go @@ -41,7 +41,6 @@ func (t *transport) Finger(ctx context.Context, targetUsername string, targetDom } req.Header.Add("Accept", string(api.AppJSON)) req.Header.Add("Accept", "application/jrd+json") - req.Header.Add("User-Agent", t.controller.userAgent) req.Header.Set("Host", req.URL.Host) // Perform the HTTP request diff --git a/internal/transport/transport.go b/internal/transport/transport.go index d62701ecc..feebfd5ed 100644 --- a/internal/transport/transport.go +++ b/internal/transport/transport.go @@ -134,6 +134,8 @@ func (t *transport) do(r *http.Request, signer func(*http.Request) error, retryO {"url", r.URL.String()}, }...) + r.Header.Set("User-Agent", t.controller.userAgent) + for i := 0; i < maxRetries; i++ { // Reset signing header fields now := t.controller.clock.Now().UTC()