...

Text file src/github.com/hashicorp/go-cleanhttp/README.md

Documentation: github.com/hashicorp/go-cleanhttp

     1# cleanhttp
     2
     3Functions for accessing "clean" Go http.Client values
     4
     5-------------
     6
     7The Go standard library contains a default `http.Client` called
     8`http.DefaultClient`. It is a common idiom in Go code to start with
     9`http.DefaultClient` and tweak it as necessary, and in fact, this is
    10encouraged; from the `http` package documentation:
    11
    12> The Client's Transport typically has internal state (cached TCP connections),
    13so Clients should be reused instead of created as needed. Clients are safe for
    14concurrent use by multiple goroutines.
    15
    16Unfortunately, this is a shared value, and it is not uncommon for libraries to
    17assume that they are free to modify it at will. With enough dependencies, it
    18can be very easy to encounter strange problems and race conditions due to
    19manipulation of this shared value across libraries and goroutines (clients are
    20safe for concurrent use, but writing values to the client struct itself is not
    21protected).
    22
    23Making things worse is the fact that a bare `http.Client` will use a default
    24`http.Transport` called `http.DefaultTransport`, which is another global value
    25that behaves the same way. So it is not simply enough to replace
    26`http.DefaultClient` with `&http.Client{}`.
    27
    28This repository provides some simple functions to get a "clean" `http.Client`
    29-- one that uses the same default values as the Go standard library, but
    30returns a client that does not share any state with other clients.

View as plain text