Skip to main content

Configure via HttpClientConfig

use Cognesy\Http\Config\HttpClientConfig;
use Cognesy\Http\Creation\HttpClientBuilder;

$config = new HttpClientConfig(
    driver: 'guzzle',
    connectTimeout: 2,
    requestTimeout: 20,
    streamChunkSize: 512,
    streamHeaderTimeout: 5,
    failOnError: true,
);

$client = (new HttpClientBuilder())
    ->withConfig($config)
    ->create();
// @doctest id="7da0"

Configure via DSN

use Cognesy\Http\Creation\HttpClientBuilder;

$client = (new HttpClientBuilder())
    ->withDsn('driver=symfony,connectTimeout=2,requestTimeout=20,streamHeaderTimeout=5,failOnError=true')
    ->create();
// @doctest id="cb7c"
DSN values are coerced to the typed HttpClientConfig fields (int, bool, string).

Preset + Override Pattern

use Cognesy\Http\Config\HttpClientConfig;
use Cognesy\Http\Creation\HttpClientBuilder;

$client = (new HttpClientBuilder())
    ->withPreset('guzzle')
    ->withConfig(new HttpClientConfig(driver: 'guzzle', failOnError: true))
    ->create();
// @doctest id="3340"
When withConfig(...) is provided, that config is authoritative.

Pool and Error Behavior

HttpClientConfig also controls:
  • maxConcurrent and poolTimeout for pooling defaults
  • failOnError for exception-on-4xx/5xx behavior
  • streamChunkSize for adapter streaming chunk size
  • streamHeaderTimeout for streaming header priming timeout (curl driver)

See Also