Repository navigation
ext/curl: Add CURLOPT_OPENSOCKETFUNCTION - #25410
Closed
nicolas-grekas wants to merge 1 commit into
Closed
nicolas-grekas wants to merge 1 commit into
nicolas-grekas wants to merge 1 commit into
Conversation
nicolas-grekas
force-pushed
the
curl-opensocketfunction
branch
from
November 12, 2026 09:35
8d3b3c7 to
36b4322
Compare
The callback is called after DNS resolution and before connect(), with the address and the port libcurl is about to connect to. Returning true lets libcurl create the socket, returning false refuses the address. This makes it possible to block requests to internal addresses before any connection is made, which CURLOPT_PREREQFUNCTION can't do.
nicolas-grekas
force-pushed
the
curl-opensocketfunction
branch
from
November 12, 2026 11:27
36b4322 to
96fd568
Compare
Contributor
Author
|
Let me close in favor of #25414, which now has the same signature. |
xavierleune
added a commit
to xavierleune/php-src
that referenced
this pull request
Nov 12, 2026
…n exception An exception thrown after the callback returned true, e.g. by a destructor, left both true and a pending exception, so the socket was still created. Also take the test that refusing an address makes libcurl try the next one from php#25410.
xavierleune
added a commit
to xavierleune/php-src
that referenced
this pull request
Nov 12, 2026
…n exception An exception thrown after the callback returned true, e.g. by a destructor, left both true and a pending exception, so the socket was still created. Also take the test that refusing an address makes libcurl try the next one from php#25410. Co-authored-by: Nicolas Grekas <nicolas.grekas@gmail.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.
This is an alternative to #23657, following the discussion there.
The callback is called before connect(), so it can block requests to internal addresses. CURLOPT_PREREQFUNCTION can't do that because it's called once the connection is made.
This uses the libcurl option as suggested by @arnaud-lb, but the callback returns a bool instead of a socket. true lets libcurl create the socket, false makes libcurl try the next address. Returning a socket can be added later by widening the return type, and more arguments can be added at the end.
A UNIX socket is reported as its path with port 0, the same as CURLOPT_PREREQFUNCTION and CURLINFO_PRIMARY_IP do. There's no address family enum, since the address is enough to tell IPv4, IPv6 and UNIX sockets apart.
The commit is authored by @xavierleune since it reuses most of the code and tests of #23657.
/cc @bukka @TimWolla