this repo has no description
0
fork

Configure Feed

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

identity: use shared http.Client for lookups, and close resp bodies (#565)

I think these were embarrassing oversights?

For PLC in particular, want to keep HTTP/2 connections open for reuse.
Less of a thing for the well-known lookups, though for the common case
of `*.bsky.social` lookups, there are lots of hostnames, but all the
same backing server, so hopefully still works.

`did:web` we might actually want a separate connection every time.

authored by

bnewbold and committed by
GitHub
4ef89d60 f687b852

+14 -3
+13 -3
atproto/identity/did.go
··· 65 65 return nil, fmt.Errorf("did:web hostname has disallowed TLD: %s", hostname) 66 66 } 67 67 68 - // TODO: use a more robust client 69 68 // TODO: allow ctx to specify unsafe http:// resolution, for testing? 70 69 71 70 if d.DIDWebLimitFunc != nil { ··· 74 73 } 75 74 } 76 75 77 - resp, err := http.Get("https://" + hostname + "/.well-known/did.json") 76 + req, err := http.NewRequestWithContext(ctx, "GET", "https://"+hostname+"/.well-known/did.json", nil) 77 + if err != nil { 78 + return nil, fmt.Errorf("constructing HTTP request for did:web resolution: %w", err) 79 + } 80 + resp, err := d.HTTPClient.Do(req) 81 + 78 82 // look for NXDOMAIN 79 83 var dnsErr *net.DNSError 80 84 if errors.As(err, &dnsErr) { ··· 85 89 if err != nil { 86 90 return nil, fmt.Errorf("%w: did:web HTTP well-known fetch: %w", ErrDIDResolutionFailed, err) 87 91 } 92 + defer resp.Body.Close() 88 93 if resp.StatusCode == http.StatusNotFound { 89 94 return nil, fmt.Errorf("%w: did:web HTTP status 404", ErrDIDNotFound) 90 95 } ··· 115 120 } 116 121 } 117 122 118 - resp, err := http.Get(plcURL + "/" + did.String()) 123 + req, err := http.NewRequestWithContext(ctx, "GET", plcURL+"/"+did.String(), nil) 124 + if err != nil { 125 + return nil, fmt.Errorf("constructing HTTP request for did:plc resolution: %w", err) 126 + } 127 + resp, err := d.HTTPClient.Do(req) 119 128 if err != nil { 120 129 return nil, fmt.Errorf("%w: PLC directory lookup: %w", ErrDIDResolutionFailed, err) 121 130 } 131 + defer resp.Body.Close() 122 132 if resp.StatusCode == http.StatusNotFound { 123 133 return nil, fmt.Errorf("%w: PLC directory 404", ErrDIDNotFound) 124 134 }
+1
atproto/identity/handle.go
··· 143 143 } 144 144 return "", fmt.Errorf("%w: HTTP well-known request error: %w", ErrHandleResolutionFailed, err) 145 145 } 146 + defer resp.Body.Close() 146 147 if resp.StatusCode == http.StatusNotFound { 147 148 return "", fmt.Errorf("%w: HTTP 404 for %s", ErrHandleNotFound, handle) 148 149 }