• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

LICENSEH A D20-Mar-201915.5 KiB

README.mdH A D20-Mar-20191.4 KiB

cleanhttp.goH A D20-Mar-20191.8 KiB

doc.goH A D20-Mar-20191.1 KiB

go.modH A D20-Mar-201941

handlers.goH A D20-Mar-2019995

handlers_test.goH A D20-Mar-20191.4 KiB

README.md

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.
31