Skip to content

Commit

Permalink
recyle buffer if http dialer error
Browse files Browse the repository at this point in the history
  • Loading branch information
phuslu committed Oct 10, 2024
1 parent db85cb8 commit 7b3f0aa
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions client_dailer.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (c *httpConn) Write(b []byte) (n int, err error) {

resp, err := tr.RoundTrip(req)
if err != nil {
return 0, fmt.Errorf("fastdnshttpdailer: roundtrip %s error: %w", c.dialer.Endpoint, err)
return 0, fmt.Errorf("fastdns: roundtrip %s error: %w", c.dialer.Endpoint, err)
}
defer resp.Body.Close()

Expand All @@ -78,10 +78,11 @@ func (c *httpConn) Write(b []byte) (n int, err error) {

_, err = io.Copy(c.buffer, resp.Body)
if err != nil {
return 0, fmt.Errorf("fastdnshttpdailer: read from %s error: %w", c.dialer.Endpoint, err)
return 0, fmt.Errorf("fastdns: read from %s error: %w", c.dialer.Endpoint, err)
}
if resp.StatusCode != http.StatusOK || resp.ContentLength <= 0 {
return 0, fmt.Errorf("fastdnshttpdailer: read from %s error: %s: %s", c.dialer.Endpoint, resp.Status, c.buffer.B)
defer bufferpool.Put(c.buffer)
return 0, fmt.Errorf("fastdns: read from %s error: %s: %s", c.dialer.Endpoint, resp.Status, c.buffer.B)
}

c.data = c.buffer.B
Expand Down

0 comments on commit 7b3f0aa

Please sign in to comment.