Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Symfony HTTP Client Compatibility Issue - Let's Fix It!#415

Open
ahmed-bhs wants to merge 25 commits intophp-vcr:masterfrom
ahmed-bhs:fix/symfony-http-client-compatibility
Open

Symfony HTTP Client Compatibility Issue - Let's Fix It!#415
ahmed-bhs wants to merge 25 commits intophp-vcr:masterfrom
ahmed-bhs:fix/symfony-http-client-compatibility

Conversation

@ahmed-bhs
Copy link

Hey PHP VCR team!

I hope this message finds you well! I’ve stumbled upon a compatibility issue between PHP VCR and the Symfony HTTP Client that I'd love to help resolve. Currently, I’m facing this friendly little roadblock:

RuntimeException: Unexpected error, could not find curl_getinfo in response or errors

This issue has already been raised here: #329, and I believe we can make a positive impact by addressing it!

Why Symfony HTTP Client Rocks

The component is compatible with four distinct HTTP client abstractions: Symfony Contracts, PSR-18, HTTPlug v1/v2, and native PHP streams. This ensures seamless integration with any application that relies on these libraries.

The Symfony HTTP Client is a standout in the PHP community, known for its extensive features and wide adoption. Its interoperability with these HTTP abstractions offers significant advantages

I’ve put together a patch that enhances the extraction of cURL info in the curlHook. By adding these essential properties to the cURL info list:

\CURLINFO_PRIVATE
\CURLINFO_CERTINFO

We can empower PHP VCR to effortlessly retrieve certificate information and private data when using the Symfony HTTP Client.

I believe this contribution will significantly improve compatibility for Symfony projects, and I’m excited to collaborate with you to make it happen. Thank you for considering this fix !

@higidi
Copy link
Contributor

higidi commented Oct 30, 2024

I'm currently a little bit busy, generally looks fine for me. Can you fix the pipeline please?

@higidi higidi added Bug Something isn't working Status: Needs work labels Oct 30, 2024
@higidi higidi self-requested a review October 30, 2024 19:44
@higidi higidi added this to the 1.10 milestone Oct 30, 2024
@ahmed-bhs
Copy link
Author

I'm currently a little bit busy, generally looks fine for me. Can you fix the pipeline please?

Hey @higidi ! Thanks a lot for your consideration. The pipeline has just been fixed and ready to go!

@higidi
Copy link
Contributor

higidi commented Oct 31, 2024

@ahmed-bhs pipeline still fails. I hope i'll get a slot to review your changes in detail this weekend.

@higidi higidi modified the milestones: 1.10, 1.9 Oct 31, 2024
@higidi
Copy link
Contributor

higidi commented Dec 10, 2024

@ahmed-bhs ?

@specialtactics
Copy link
Contributor

@higidi There is a problem with your pipelines in this package, same as my PR here #413

Can you please have a look at it and sort it out?

@specialtactics
Copy link
Contributor

Hey @ahmed-bhs can I please invite you to make these changes on our fork of this? We have maintained it for years now, since the support here is patchy

https://github.com/CoverGenius/php-vcr

@ahmed-bhs
Copy link
Author

Hey @specialtactics,

I know how it is with open-source—everyone’s busy, myself included 😅. I saw that the pipeline on PR #413 isn’t passing at the moment, but I’ll try to give you a quick hand with the tests.

Regarding the Symfony HTTP Client integration I’m working on, it’s turning out to be a bit trickier than I expected. Once my changes get approved here, it would be awesome if you could turn your recent modifications from your fork CoverGenius/php-vcr into PRs on this repository. That way we can review everything in one place and make life a bit easier for everyone.

Add symfony/http-client ^6.4|^7.0 as dev dependency and update
PHPUnit to ^9.6 for better compatibility with PHP 8.x
Replace native PHP assertions with beberlei/assert for better error
messages and validation. Ensure required keys exist before accessing
them to prevent undefined array key warnings.
Add UrlReconstructor utility to rebuild complete URLs from parsed
components. Handles edge cases like missing schemes, invalid URLs,
and proper port handling (removes default ports 80/443).
- Add curlClose() method for proper resource cleanup
- Clean up handles with NULL callbacks in disable()
- Snapshot curl options before execution to prevent TraceableHttpClient issues
- Add special handling for CURLINFO_PRIVATE
- Improve gzip decompression with proper Accept-Encoding handling
Make wrapper_data property public to ensure stream_get_meta_data()
compatibility with NativeHttpClient. Add proper header handling for
both string and array formats.
Add namespaced proxy function to intercept stream_get_meta_data() calls
in Symfony\Component\HttpClient\Response namespace. This converts
StreamWrapperHook objects to arrays for NativeHttpClient compatibility.
Add wrapper class that adapts VCR Response objects to Symfony's
ResponseInterface. Handles header normalization, status codes, and
content retrieval with proper error handling.
Add main wrapper that intercepts Symfony HttpClient requests and
replays VCR responses. Handles:
- Automatic gzip decompression
- Streaming responses
- Request options normalization
- Error handling and exceptions
Add specialized wrapper for NativeHttpClient that extends VCRHttpClient
with additional compatibility fixes for PHP stream-based implementation.
Add helper class to convert between VCR Request/Response and Symfony
format. Handles header normalization, body conversion, and proper
HTTP method/URL extraction.
Add AST transformer that automatically wraps 'new CurlHttpClient()'
and 'new NativeHttpClient()' instantiations with VCRHttpClient.
Uses nikic/php-parser to modify code at runtime.
Add library hook that registers SymfonyHttpClientCodeTransform
for automatic client wrapping. Integrates with VCR's code
transformation system.
- Register 'symfony_http_client' hook in available hooks
- Add cache directories to transformation blacklist
- Update VCRFactory to instantiate the new hook
Add SymfonyHttpClientTestTrait with helper methods for testing
Symfony HttpClient with VCR. Simplifies test setup and provides
utility methods for common testing scenarios.
Add comprehensive integration tests covering:
- CurlHttpClient (GET, POST, PUT, DELETE)
- NativeHttpClient (GET, POST, PUT, DELETE)
- MockHttpClient
- TraceableHttpClient

Includes JsonPlaceholderClient helper for testing real API calls.
Test individual Symfony HttpClient implementations:
- CurlHttpClient with various options
- NativeHttpClient with stream_get_meta_data
- VCRNativeHttpClient wrapper
- ScopingHttpClient with multiple scopes
- TraceableHttpClient with request tracing
Test specific features:
- Authentication (Basic Auth, Bearer tokens)
- Concurrent/async requests
- Custom options (headers, timeout, user_data, query params)
- Error handling and edge cases
Test hook behavior:
- Code transformation effectiveness
- CurlHttpClient with curl hooks only (no transformation)
- NativeHttpClient with stream_wrapper hooks only
Add 38 cassette files with recorded HTTP responses for:
- CRUD operations (GET, POST, PUT, DELETE)
- Authentication scenarios
- Custom options and headers
- Multiple client types
- Error cases
Add comprehensive documentation explaining:
- When to use high-level vs low-level hooks
- VCRHttpClient vs CurlHook trade-offs
- Architecture decisions and design rationale
- Gzip decompression handling with Symfony
Add complete usage guide with:
- Automatic wrapping example (recommended)
- Manual wrapping alternative
- List of supported clients
- How it works explanation
- Link to HOOK_STRATEGY.md
Update baseline to reflect new code and fix reported issues
in Symfony HttpClient integration files.
- Ignore only dynamic cassettes (cassette* pattern)
- Update test files to use correct paths
@ahmed-bhs ahmed-bhs force-pushed the fix/symfony-http-client-compatibility branch from 17ab29e to dc3124c Compare October 7, 2025 16:57
@ahmed-bhs
Copy link
Author

This turned out to be more work than I first thought, especially since Symfony HTTP Client has a really complex response compression/decompression gzip logic and doesn’t always work seamlessly. @higidi and @specialtactics , I’d really appreciate it if you could review the code or at least test it out in a real project whenever you have some free time.

@ahmed-bhs ahmed-bhs force-pushed the fix/symfony-http-client-compatibility branch from b558c9a to 2978839 Compare October 7, 2025 19:16
@specialtactics
Copy link
Contributor

@ahmed-bhs unfortunately I am not longer working for my previous employer where those projects are, I will try and find someone who could try it.

I will have a review of the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants