On Sun, Apr 17, 2022 at 06:52:17AM -0700, Toon Knapen wrote: > It is not clear to me from the documentation whether I can continue to use > an http.Client after a POST failed (due to the connection being closed ; > In my case the connection closes probably due to rate-limiting). > > The documentation of the http.Transport does mention that, if a network > error occurs, it will retry if the request is idempotent. Given I'm doing a > basicPOST that is not the case for me. > > But the http.Client will reestablish the connection on the next call to > Post(...) ?
It won't be http.Client who will reestablish the connection, but whatever implementation supporting the http.RoundTripper interface provided in the Transport field of the http.Client. If that field is not set, the default http.DefaultTransport will be used, which is an instance of http.Transport. Basically the idea is that an http.Transport first tries to pick a live but idle TCP connection from its pool of idle connections, and if there are none, it tries to establish a new one. I'd undeline the idea is that an http.Client is not something akin to a single invocation of `curl`; instead it's a shared client-side HTTP request "multiplexer" which is OK to be used for multiple concurrent HTTP requests wihch will share a single http.RoundTripper configured to be used for that http.Client (as explained above), and it, in turn, is responsible for maintaining a pool of ready-to-use connections, any number of which can be used to carry out HTTP requests concurrently. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/20220418093427.bmdwdtbttppi4aqm%40carbon.