Skip to content

Issue/566 native curl adapter#568

Open
armanist wants to merge 10 commits into
quantum-php:masterfrom
armanist:issue/566-native-curl-adapter
Open

Issue/566 native curl adapter#568
armanist wants to merge 10 commits into
quantum-php:masterfrom
armanist:issue/566-native-curl-adapter

Conversation

@armanist

@armanist armanist commented Jul 18, 2026

Copy link
Copy Markdown
Collaborator

Closes #566

Summary by CodeRabbit

  • Changed

    • Single HTTP requests now use native cURL execution, while multi-request handling continues through the existing adapter.
    • Response headers, cookies, JSON/XML content, compression, and HTTP errors are handled consistently.
    • Existing request configuration and response access remain supported.
  • Tests

    • Expanded coverage for native request execution, response parsing, cookies, errors, and compatibility behavior.

@armanist armanist added the enhancement New feature or request label Jul 18, 2026
@armanist armanist added this to the 3.1.0 milestone Jul 18, 2026
@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@armanist, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 4 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: d006b792-a36a-4eff-a2f2-6c3133ad1f24

📥 Commits

Reviewing files that changed from the base of the PR and between be7732c and bb12b3c.

📒 Files selected for processing (3)
  • src/HttpClient/Adapters/CurlAdapter.php
  • tests/Unit/HttpClient/Adapters/CurlAdapterTest.php
  • tests/Unit/HttpClient/HttpClientTest.php
📝 Walkthrough

Walkthrough

CurlAdapter now uses native PHP cURL for single requests, with local request/response state, header and cookie parsing, response decoding, error handling, and compatibility with injected clients. Unit tests and the changelog were updated accordingly.

Changes

Native CurlAdapter execution

Layer / File(s) Summary
Adapter state and configuration
src/HttpClient/Adapters/CurlAdapter.php
CurlAdapter initializes native cURL state, applies URLs, options, and headers locally, and preserves injected-client delegation.
Native execution and response parsing
src/HttpClient/Adapters/CurlAdapter.php
Native requests execute through cURL, with parsed headers, cookies, JSON/XML/gzip responses, metadata, and errors exposed through the adapter API.
Compatibility and validation
tests/Unit/HttpClient/Adapters/CurlAdapterTest.php, tests/Unit/HttpClient/HttpClientTest.php, CHANGELOG.md
Tests cover native and transition-bridge behavior, while HttpClient expectations and the 3.1.0 changelog entry reflect the migration.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant HttpClient
  participant CurlAdapter
  participant NativePHPcURL
  HttpClient->>CurlAdapter: configure request
  CurlAdapter->>NativePHPcURL: execute native curl request
  NativePHPcURL-->>CurlAdapter: return raw response and status
  CurlAdapter-->>HttpClient: return parsed response state
Loading

Possibly related issues

Possibly related PRs

Suggested labels: http

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately describes the native CurlAdapter change.
Linked Issues check ✅ Passed The native single-request CurlAdapter, compatibility behavior, and focused tests align with issue #566's requirements.
Out of Scope Changes check ✅ Passed The only extra change is a changelog note, which is in scope for documenting the adapter rewrite.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov-commenter

codecov-commenter commented Jul 18, 2026

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 95.33333% with 7 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/HttpClient/Adapters/CurlAdapter.php 95.33% 7 Missing ⚠️

📢 Thoughts on this report? Let us know!

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: be7732ced4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/HttpClient/Adapters/CurlAdapter.php
Comment thread src/HttpClient/Adapters/CurlAdapter.php Outdated
Comment thread src/HttpClient/Adapters/CurlAdapter.php Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/HttpClient/Adapters/CurlAdapter.php (2)

134-151: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Store request headers case-insensitively.

Different casing currently creates duplicate headers and can make hasJsonContentType() use a superseded value. Normalize names before assignment.

Proposed fix
 public function setHeader(string $key, $value): CurlAdapterInterface
 {
-    $this->headers[$key] = $value;
+    $this->headers[strtolower(trim($key))] = $value;
     $this->applyHeaders();

     return $this;
 }
@@
-    $this->headers[trim((string) $key)] = trim((string) $value);
+    $this->headers[strtolower(trim((string) $key))] = trim((string) $value);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/HttpClient/Adapters/CurlAdapter.php` around lines 134 - 151, Normalize
header names case-insensitively before storing them in both setHeader and
setHeaders, using a consistent lowercase representation so differently cased
names overwrite the same entry. Preserve the existing value trimming behavior in
setHeaders and ensure applyHeaders continues using the normalized headers.

101-151: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Forward request setters to the injected client.
src/HttpClient/Adapters/CurlAdapter.php still writes URL/header/option state only to the adapter’s native handle. In bridge mode, start() executes $this->client->exec(), so those settings never reach the client that actually runs. Add a regression in tests/Unit/HttpClient/Adapters/CurlAdapterTest.php for setUrl() and representative header/option forwarding.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/HttpClient/Adapters/CurlAdapter.php` around lines 101 - 151, The setter
methods setUrl(), setOpt(), setOpts(), setHeader(), and setHeaders() must
forward applied URL, option, and header values to the injected client used by
start(), while preserving native-handle behavior. Update CurlAdapter.php
accordingly, and add regression coverage in
tests/Unit/HttpClient/Adapters/CurlAdapterTest.php at lines 135-136 for setUrl()
plus representative header and option forwarding.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/HttpClient/Adapters/CurlAdapter.php`:
- Around line 369-386: Update parseResponse to handle gzip Content-Encoding
before content-type deserialization: detect the encoding case-insensitively,
decompress into $response when successful, and retain the raw response on
failure. Then pass $response—not $rawResponse—to json_decode() and
simplexml_load_string(), preserving existing fallback behavior.
- Around line 214-218: Update the error-message assignment in CurlAdapter’s
response handling so $this->errorMessage is populated only when $this->error is
true; retain the cURL error details for cURL failures and the status-line
fallback for HTTP errors, while leaving it null on successful requests.
- Around line 319-323: Update parseCookieHeader to match and store empty cookie
values in Set-Cookie headers, including deletion headers such as sid=;
Max-Age=0. Adjust the value capture so the cookie entry is updated with an empty
string instead of retaining a stale earlier value, while preserving existing
decoding and trimming behavior.
- Around line 379-381: Update the XML parsing branch in CurlAdapter to enable
libxml internal errors before calling simplexml_load_string(), then restore the
previous libxml error setting afterward even when parsing fails. Preserve the
existing SimpleXMLElement return and raw response fallback behavior.

---

Outside diff comments:
In `@src/HttpClient/Adapters/CurlAdapter.php`:
- Around line 134-151: Normalize header names case-insensitively before storing
them in both setHeader and setHeaders, using a consistent lowercase
representation so differently cased names overwrite the same entry. Preserve the
existing value trimming behavior in setHeaders and ensure applyHeaders continues
using the normalized headers.
- Around line 101-151: The setter methods setUrl(), setOpt(), setOpts(),
setHeader(), and setHeaders() must forward applied URL, option, and header
values to the injected client used by start(), while preserving native-handle
behavior. Update CurlAdapter.php accordingly, and add regression coverage in
tests/Unit/HttpClient/Adapters/CurlAdapterTest.php at lines 135-136 for setUrl()
plus representative header and option forwarding.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 8902f2d0-6795-46db-8ec0-cac9c69329c0

📥 Commits

Reviewing files that changed from the base of the PR and between c0aa53b and be7732c.

📒 Files selected for processing (4)
  • CHANGELOG.md
  • src/HttpClient/Adapters/CurlAdapter.php
  • tests/Unit/HttpClient/Adapters/CurlAdapterTest.php
  • tests/Unit/HttpClient/HttpClientTest.php
💤 Files with no reviewable changes (1)
  • tests/Unit/HttpClient/HttpClientTest.php

Comment thread src/HttpClient/Adapters/CurlAdapter.php Outdated
Comment thread src/HttpClient/Adapters/CurlAdapter.php
Comment thread src/HttpClient/Adapters/CurlAdapter.php Outdated
Comment thread src/HttpClient/Adapters/CurlAdapter.php Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement native HttpClient CurlAdapter for single requests

2 participants