Skip to content

Installation

phil/safe-http
composer require phil/safe-http
PackageVersionUsed for
PHP8.5 or later, with the mbstring and URI extensionsThe messages of the exceptions, the resolution of redirects
phil/url^0.1The addresses
symfony/http-client, symfony/http-client-contracts^8.2, ^3.6The transport and NoPrivateNetworkHttpClient
symfony/http-foundation^8.2IpUtils, the private ranges
symfony/service-contracts^3.6ResetInterface

In a Symfony application, register one client per use, each with its limits, and tag it kernel.reset with the method reset:

$services->set('app.feed_client', SafeHttpClient::class)
    ->args([service('http_client')->nullOnInvalid(), inline_service(Limits::class)->args([5.0, 20.0, 4_194_304, 3, 'ExampleBot/1.0 (+https://example.com/bot)'])])
    ->tag('kernel.reset', ['method' => 'reset']);