Reusing http connections in Golang

前端 未结 9 809
时光取名叫无心
时光取名叫无心 2020-12-02 04:27

I\'m currently struggling to find a way to reuse connections when making HTTP posts in Golang.

I\'ve created a transport and client like so:

// Crea         


        
9条回答
  •  独厮守ぢ
    2020-12-02 05:04

    IIRC, the default client does reuse connections. Are you closing the response?

    Callers should close resp.Body when done reading from it. If resp.Body is not closed, the Client's underlying RoundTripper (typically Transport) may not be able to re-use a persistent TCP connection to the server for a subsequent "keep-alive" request.

提交回复
热议问题