[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.
This commit is contained in:
Daniele Sluijters 2022-11-26 21:19:42 +01:00 committed by GitHub
parent d6f4d196c9
commit c5ae88c51b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 2 additions and 7 deletions

View file

@ -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("Content-Type", string(api.AppActivityLDJSON))
req.Header.Add("Accept-Charset", "utf-8") req.Header.Add("Accept-Charset", "utf-8")
req.Header.Add("User-Agent", t.controller.userAgent)
req.Header.Set("Host", to.Host) req.Header.Set("Host", to.Host)
resp, err := t.POST(req, b) resp, err := t.POST(req, b)

View file

@ -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", string(api.AppActivityLDJSON)+","+string(api.AppActivityJSON))
req.Header.Add("Accept-Charset", "utf-8") req.Header.Add("Accept-Charset", "utf-8")
req.Header.Add("User-Agent", t.controller.userAgent)
req.Header.Set("Host", iri.Host) req.Header.Set("Host", iri.Host)
// Perform the HTTP request // Perform the HTTP request

View file

@ -93,7 +93,6 @@ func dereferenceByAPIV1Instance(ctx context.Context, t *transport, iri *url.URL)
} }
req.Header.Add("Accept", string(api.AppJSON)) req.Header.Add("Accept", string(api.AppJSON))
req.Header.Add("User-Agent", t.controller.userAgent)
req.Header.Set("Host", cleanIRI.Host) req.Header.Set("Host", cleanIRI.Host)
resp, err := t.GET(req) resp, err := t.GET(req)
@ -244,7 +243,6 @@ func callNodeInfoWellKnown(ctx context.Context, t *transport, iri *url.URL) (*ur
return nil, err return nil, err
} }
req.Header.Add("Accept", string(api.AppJSON)) req.Header.Add("Accept", string(api.AppJSON))
req.Header.Add("User-Agent", t.controller.userAgent)
req.Header.Set("Host", cleanIRI.Host) req.Header.Set("Host", cleanIRI.Host)
resp, err := t.GET(req) resp, err := t.GET(req)
@ -296,7 +294,6 @@ func callNodeInfo(ctx context.Context, t *transport, iri *url.URL) (*apimodel.No
return nil, err return nil, err
} }
req.Header.Add("Accept", string(api.AppJSON)) req.Header.Add("Accept", string(api.AppJSON))
req.Header.Add("User-Agent", t.controller.userAgent)
req.Header.Set("Host", iri.Host) req.Header.Set("Host", iri.Host)
resp, err := t.GET(req) resp, err := t.GET(req)

View file

@ -36,7 +36,6 @@ func (t *transport) DereferenceMedia(ctx context.Context, iri *url.URL) (io.Read
return nil, 0, err 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("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) req.Header.Set("Host", iri.Host)
// Perform the HTTP request // Perform the HTTP request

View file

@ -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", string(api.AppJSON))
req.Header.Add("Accept", "application/jrd+json") req.Header.Add("Accept", "application/jrd+json")
req.Header.Add("User-Agent", t.controller.userAgent)
req.Header.Set("Host", req.URL.Host) req.Header.Set("Host", req.URL.Host)
// Perform the HTTP request // Perform the HTTP request

View file

@ -134,6 +134,8 @@ func (t *transport) do(r *http.Request, signer func(*http.Request) error, retryO
{"url", r.URL.String()}, {"url", r.URL.String()},
}...) }...)
r.Header.Set("User-Agent", t.controller.userAgent)
for i := 0; i < maxRetries; i++ { for i := 0; i < maxRetries; i++ {
// Reset signing header fields // Reset signing header fields
now := t.controller.clock.Now().UTC() now := t.controller.clock.Now().UTC()