Skip to content

Support CURLOPT_PREREQFUNCTION in coroutine curl handler - #190

Merged
deminy merged 1 commit into
swoole:masterfrom
lazerg:fix/curl-prereqfunction
Jul 28, 2026
Merged

deminy merged 1 commit into
swoole:masterfrom
lazerg:fix/curl-prereqfunction

Conversation

@lazerg

@lazerg lazerg commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Guzzle 7.13 registers CURLOPT_PREREQFUNCTION and sets it back to null when it releases each handle. Under SWOOLE_HOOK_CURL that call lands in Handler::setOption(), which doesn't know the option and throws swoole_curl_setopt(): option[20312] is not supported, so every request made through Guzzle blows up. This accepts the option the same way the other callback options are handled. The constant only exists on PHP 8.2+ with libcurl 7.80 or newer, so it's guarded with defined() to avoid breaking older builds.

Fixes swoole/swoole-src#6098

@lazerg

lazerg commented Jul 25, 2026 •

Copy link
Copy Markdown
Contributor Author

These failures don't look related to this change.

@deminy
deminy self-requested a review July 27, 2026 04:23
@deminy deminy self-assigned this Jul 27, 2026
@deminy
deminy merged commit 7b58e9f into swoole:master Jul 28, 2026
7 of 15 checks passed
deminy added a commit that referenced this pull request Jul 28, 2026
Polish the CURLOPT_PREREQFUNCTION support added in PR #190:

- Polyfill CURLOPT_PREREQFUNCTION, CURL_PREREQFUNC_OK and
  CURL_PREREQFUNC_ABORT in src/constants.php (like the other
  libcurl-version-gated CURLOPT_* constants), turning the special-cased
  default: branch of Handler::setOption() into a plain case.
- Actually invoke the callback before each request (once per redirect
  hop) with the five native arguments; real socket addresses are
  reported when an established connection is reused. Returning
  CURL_PREREQFUNC_ABORT aborts the transfer with
  CURLE_ABORTED_BY_CALLBACK before any I/O, and other return values
  throw ValueError/TypeError as native cURL does.
- Replace the setopt-only test with behavioral tests against the local
  httpbin service: invocation and arguments, per-hop invocation on
  redirects, abort semantics, invalid return values, and clearing the
  callback with null (Guzzle's release path).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

swoole_curl_setopt(): option[20312] is not supported

2 participants