Provides clean, isolated HTTP clients in Go that avoid shared state issues with the standard library's default client.
cleanhttp is a Go library that provides functions to obtain "clean" HTTP client instances. It solves the problem of shared state and race conditions that occur when multiple libraries or goroutines modify the global `http.DefaultClient` or its default transport.
Go developers building applications or libraries that make HTTP requests and need to avoid interference from dependencies that might modify shared HTTP client state.
Developers choose cleanhttp because it offers a simple, reliable way to get isolated HTTP clients with standard defaults, preventing subtle bugs and race conditions without requiring manual client configuration or reinventing the wheel.
cleanhttp offers simple functions to obtain "clean" http.Client instances in Go. These clients use the same default configurations as the standard library but are isolated, preventing the race conditions and strange bugs that can arise from libraries modifying shared global clients like http.DefaultClient.
http.DefaultClient, ensuring familiar behavior.cleanhttp.DefaultClient() to get a clean client without manual configuration.cleanhttp follows the Go philosophy of simplicity and explicitness, providing minimal, focused utilities that solve a specific, common pain point in Go HTTP client usage.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
By providing isolated HTTP clients, cleanhttp eliminates the risk of race conditions caused by multiple libraries modifying the shared `http.DefaultClient` or `http.DefaultTransport`, as explained in the README.
The clients use the same default transport and timeouts as Go's standard library, ensuring familiar behavior without additional configuration, which is a core feature highlighted in the README.
With straightforward functions like `cleanhttp.DefaultClient()`, it reduces boilerplate code for safe HTTP client initialization, making it easy to adopt in existing projects.
Clients are safe for concurrent use by multiple goroutines, adhering to Go's best practices for HTTP client reuse, as stated in the README's philosophy.
cleanhttp focuses solely on client isolation and does not include advanced features like automatic retries, circuit breaking, or custom timeout settings, which are often needed in production applications.
For simple applications or those with no external dependencies, using cleanhttp might add unnecessary complexity compared to directly using `http.DefaultClient` with caution, as the README acknowledges the problem is more prevalent with many dependencies.
It introduces an external dependency for functionality that could be implemented with a few lines of custom code, increasing project maintenance overhead without adding significant new capabilities.