$ show symfony/http-client-contracts
This repository provides a set of PHP interfaces (contracts) for HTTP client operations, extracted from the Symfony framework. It defines the core abstractions: HttpClientInterface for issuing requests, ResponseInterface for lazy response handling, ChunkInterface for streaming response chunks, and ResponseStreamInterface for iterating over chunks from multiple responses. A full hierarchy of exception interfaces (Transport, Client, Server, Redirection, Timeout, Decoding) is included, along with a reference test suite (HttpClientTestCase) that validates any implementation against a set of comprehensive scenarios. The package contains no concrete implementations; it is purely a contract to ensure interoperability among different HTTP client libraries. The code is clean, well-documented, and leverages modern PHP 8.1 features like mixed types and static return types. It is actively maintained with zero open issues and follows semantic versioning as part of the Symfony contracts.
The LLM identified 3 files worth highlighting for reuse:
The core interface defining a flexible HTTP client with lazy responses, streaming, and support for a wide array of options (authentication, timeouts, proxies, TLS). It uses the 'withOptions' method for immutable configuration and returns ResponseInterface and ResponseStreamInterface. This interface is the primary contract that any HTTP client implementation must fulfill, and it is designed for both synchronous and asynchronous usage.
Defines the contract for individual chunks yielded by a response stream. Methods like isFirst(), isLast(), getContent(), getOffset(), and getInformationalStatus() enable fine-grained control over streaming responses, including handling of informational (1xx) status codes and timeout detection. This interface is essential for non-blocking HTTP consumption and is cleanly separated from the response object.
An abstract PHPUnit test case that provides a comprehensive, reusable test suite for any HttpClientInterface implementation. It covers requests (GET, HEAD, POST), streaming, timeouts, redirects, encoding, proxies, and error handling. Implementers only need to provide a getHttpClient() factory method to validate their client against the same rigorous set of tests, making it a valuable pattern for ensuring interoperability.