$ show imroc/req
This repository is a Go HTTP client library named 'req' (module github.com/imroc/req/v3). It provides a high-level, fluent API for making HTTP requests with extensive features including HTTP/1.1, HTTP/2, and HTTP/3 support, automatic retries with configurable backoff and conditions, middleware chains for request/response processing, TLS fingerprint impersonation (via uTLS), bandwidth rate limiting, parallel file downloads, digest authentication, and detailed debugging capabilities (dump, trace, curl command generation). The library is designed for production use, with a focus on ease of use and flexibility, allowing developers to build custom SDKs on top of it. The architecture centers around a Client struct that holds configuration and a Transport that wraps net/http with additional capabilities. Requests are built using a builder pattern (R() method) and executed via method-specific helpers (Get, Post, etc.). The codebase includes a significant amount of internal code forked from Go's standard library (HTTP/2, chunked encoding) and third-party dependencies (quic-go for HTTP/3, brotli, zstd). It is a pure application library with no data analysis or research components.
The LLM identified 7 files worth highlighting for reuse:
Implements configurable retry logic with support for fixed, exponential backoff, and custom intervals. Retry conditions can inspect the response and error, and hooks allow mutating the request between retries. This is a self-contained pattern that can be extracted and reused in any HTTP client or similar retry scenario.
Provides per-request bandwidth limiting for both upload and download. Uses a token bucket or similar mechanism to control data transfer rates. This is a reusable rate-limiting component that can be applied to any I/O stream.
Implements parallel file download by splitting the file into segments, downloading them concurrently, and merging the results. Handles range requests and error recovery. This pattern is reusable for any HTTP-based parallel download scenario.
Implements HTTP Digest Access Authentication with automatic challenge caching and retry on 401 responses. Handles nonce counting and algorithm negotiation. This is a standalone authentication module that can be reused in any HTTP client.
Generates equivalent curl command strings from HTTP requests, including headers, body, and authentication. Useful for debugging and reproducing requests outside the library. This is a self-contained utility that can be adapted to other HTTP clients.
Automatically detects character encoding from HTTP Content-Type headers, BOM, or HTML meta tags, and decodes response bodies to UTF-8. Supports common encodings like GBK, UTF-16, etc. This is a reusable charset detection and conversion module.
Provides a unified reader interface for decompressing HTTP response bodies using gzip, deflate, brotli, and zstd. Automatically selects the appropriate decompressor based on Content-Encoding. This pattern can be extracted and reused in any HTTP client or stream processing pipeline.