Repository navigation
Add support for custom PSR-18 HTTP clients - #431
Merged
Merged
Conversation
Let applications send SDK requests through their own PSR-18 client, so their logging, retries, proxy and timeouts apply. - Cloudinary::setHttpClient() sets the client for API objects returned by uploadApi(), adminApi(), searchApi() and searchFoldersApi(). - setHttpClient() on UploadApi, AdminApi, SearchApi, SearchFoldersApi and AccountApi sets it for objects created directly. - Cloudinary::setDefaultHttpClient() sets a process-wide default. - A Guzzle handler (Psr18Handler) forwards each built request to the client and maps PSR-18 network and client errors to Guzzle exceptions, so the public API, including *Async() return types, is unchanged. - With a custom client, timeout, connection_timeout and api_proxy are owned by the client, and async calls run sequentially. - Require psr/http-client; add symfony/http-client to require-dev. - CI: add PHP 8.5; run the suite through the Symfony PSR-18 client on PHP 8.5 with Guzzle 8. - Tests: unit tests for the handler and setters; live scenario tests through Guzzle and Symfony PSR-18 clients; CLD_TEST_HTTP_CLIENT runs integration tests through a PSR-18 client. - Tests: call ReflectionMethod::setAccessible() only before PHP 8.1, as PHP 8.5 deprecates it. - Docs: docs/use-custom-http-client.md, an example, and a README section. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Brief Summary of Changes
Lets applications send SDK requests through their own PSR-18 HTTP client, so their logging, retries, proxy, and timeouts apply. Without it, the SDK keeps using its built-in Guzzle client exactly as before.
Cloudinary::setHttpClient()sets the client for API objects returned byuploadApi(),adminApi(),searchApi(), andsearchFoldersApi().setHttpClient()onUploadApi,AdminApi,SearchApi,SearchFoldersApi, andAccountApisets it for objects created directly.Cloudinary::setDefaultHttpClient()sets a process-wide default. An object's own client wins over the default, which wins over the built-in client.Psr18Handleris a Guzzle handler that forwards each built request to the PSR-18 client and maps PSR-18 network and client errors toConnectExceptionandRequestException. The public API, including*Async()return types, is unchanged.psr/http-clientis now a direct requirement (already installed through Guzzle).symfony/http-clientis added torequire-dev.ReflectionMethod::setAccessible()only before PHP 8.1; PHP 8.5 deprecates it, which failed the run.docs/use-custom-http-client.md,examples/use-custom-http-client.php, and a README section.What does this PR address?
Are tests included?
Reviewer, please note:
timeout,connection_timeout, andapi_proxyare configured on the client, not in Cloudinary configuration.*Async()calls made through a custom client run one at a time.Authorizationheader with the API secret. The docs tell users to redact it if their client logs headers.*Async()returns Guzzle promises.Checklist: