From 99c3765092e5150bf38072311376479448d53e97 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Tue, 29 Oct 2024 10:49:14 -0300 Subject: [PATCH] nip05: use a global http client. --- nip05/nip05.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/nip05/nip05.go b/nip05/nip05.go index 867b488..ca5fd07 100644 --- a/nip05/nip05.go +++ b/nip05/nip05.go @@ -56,6 +56,12 @@ func QueryIdentifier(ctx context.Context, fullname string) (*nostr.ProfilePointe }, nil } +var httpClient = &http.Client{ + CheckRedirect: func(req *http.Request, via []*http.Request) error { + return http.ErrUseLastResponse + }, +} + func Fetch(ctx context.Context, fullname string) (resp WellKnownResponse, name string, err error) { name, domain, err := ParseIdentifier(fullname) if err != nil { @@ -68,12 +74,7 @@ func Fetch(ctx context.Context, fullname string) (resp WellKnownResponse, name s return resp, name, fmt.Errorf("failed to create a request: %w", err) } - client := &http.Client{ - CheckRedirect: func(req *http.Request, via []*http.Request) error { - return http.ErrUseLastResponse - }, - } - res, err := client.Do(req) + res, err := httpClient.Do(req) if err != nil { return resp, name, fmt.Errorf("request failed: %w", err) }