thesis / http-client
Asynchronous HTTP/1 client for HTTP and HTTPS with connection pooling, streaming bodies and trailers.
Fund package maintenance!
Requires
- php: ^8.6
- thesis/http: ^0.1
- thesis/http-protocol: ^0.1
- thesis/io: ^0.1
- thesis/net: ^0.1
Requires (Dev)
- testo/assert: ^0.1.17
- testo/codecov: ^0.2.5
- testo/test: ^0.1.8
- testo/testo: ^0.10.29
- thesis/async: ^0.1
- thesis/testo-plugin: ^0.1
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-23 23:14:52 UTC
README
Thesis HTTP Client
This read-only repository mirrors
packages/http-client. Open issues and pull requests in the thesis-php/thesis monorepo.
Send an HTTP/1.1 request inside a Thesis async scope. The final response head is available as soon as
send() returns. Read the body under the deadline you want for the download. The client supplies a body that implements
Closer. Close an unfinished body to close its connection immediately. A permanent read failure or dropping the last
reference to an unfinished body also closes the connection.
use Thesis\Http\Request; use Thesis\HttpClient\Client; use Thesis\Http\Response; use Uri\Rfc3986\Uri; use function Thesis\Async\timeout; use function Thesis\Time\sec; $request = new Request('GET', new Uri('https://example.com/')); $client = new Client(); $response = timeout(sec(5), static fn() => $client->send($request)); $status = $response->status; $response->body->close();
Use withResponse() to close the body when a callback returns or throws:
$status = $client->withResponse($request, static fn(Response $response) => $response->status);
Reuse the same client across requests to share connections for the same scheme, host and port.
A fixed-length body releases its socket on the last byte. A chunked body releases it after the trailers.
$response->body->discard() consumes any remaining bytes. A bodyless response releases it immediately.
An outstanding body keeps its own socket. The client retains one idle socket per origin, up to 32 in total.
If a peer closes an idle connection, the next request opens a new one. A disconnect during a request
propagates to the caller. The client never replays an upload.
HTTPS verifies the peer through thesis/net. Pass a Net ClientTls configuration to the constructor to use a private CA. The client sends the request body before reading the response. Redirects are returned to the caller.