Repository navigation
[RFC] ext/curl: Add CURLOPT_OPENSOCKETFUNCTION #25414
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
xavierleune
wants to merge
2
commits into
php:master
Choose a base branch
from
xavierleune:feature/curl-opensocketfunction-8.7
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,059
−1
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
30 changes: 30 additions & 0 deletions
30
ext/curl/tests/curl_opensocketfunction_abstract_unix_socket.phpt
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| --TEST-- | ||
| CURLOPT_OPENSOCKETFUNCTION reports an abstract UNIX socket name with its leading NUL byte | ||
| --EXTENSIONS-- | ||
| curl | ||
| --SKIPIF-- | ||
| <?php | ||
| if (PHP_OS_FAMILY !== 'Linux') die('skip abstract UNIX sockets are Linux only'); | ||
| if (!defined('CURLOPT_ABSTRACT_UNIX_SOCKET')) die('skip CURLOPT_ABSTRACT_UNIX_SOCKET not available'); | ||
| ?> | ||
| --FILE-- | ||
| <?php | ||
| /* The leading NUL byte is part of an abstract name: keeping it tells a policy | ||
| * that the name is not a filesystem path. */ | ||
| $name = 'php-curl-' . getmypid(); | ||
|
|
||
| $ch = curl_init('http://localhost/'); | ||
| curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | ||
| curl_setopt($ch, CURLOPT_ABSTRACT_UNIX_SOCKET, $name); | ||
| curl_setopt($ch, CURLOPT_OPENSOCKETFUNCTION, function (CurlHandle $handle, string $address, int $port) use ($name): bool { | ||
| var_dump($address === "\0" . $name, $port); | ||
| return false; | ||
| }); | ||
| var_dump(curl_exec($ch)); | ||
| var_dump(curl_errno($ch) === CURLE_COULDNT_CONNECT); | ||
| ?> | ||
| --EXPECT-- | ||
| bool(true) | ||
| int(0) | ||
| bool(false) | ||
| bool(true) |
62 changes: 62 additions & 0 deletions
62
ext/curl/tests/curl_opensocketfunction_address_family.phpt
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| --TEST-- | ||
| CURLOPT_OPENSOCKETFUNCTION reports the address and port of IPv4 and IPv6 endpoints | ||
| --EXTENSIONS-- | ||
| curl | ||
| --SKIPIF-- | ||
| <?php | ||
| if (!(curl_version()['features'] & CURL_VERSION_IPV6)) die('skip libcurl built without IPv6'); | ||
| /* The IPv6 probes below rely on libcurl attempting a literal ::1 address, which | ||
| * it will not do on a host without a usable IPv6 loopback. */ | ||
| $s = @stream_socket_server('tcp://[::1]:0', $errno, $errstr); | ||
| if ($s === false) die('skip no IPv6 loopback available'); | ||
| fclose($s); | ||
| ?> | ||
| --FILE-- | ||
| <?php | ||
| /* No listener is needed: the callback runs before connect(). Proxies from the | ||
| * environment are ignored, or the callback would see the proxy instead. */ | ||
| function probe(string $url): void { | ||
| $ch = curl_init(); | ||
| curl_setopt($ch, CURLOPT_URL, $url); | ||
| curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | ||
| curl_setopt($ch, CURLOPT_PROXY, ''); | ||
| curl_setopt($ch, CURLOPT_OPENSOCKETFUNCTION, function (CurlHandle $handle, string $address, int $port): bool { | ||
| var_dump($address, $port); | ||
| return false; | ||
| }); | ||
| curl_exec($ch); | ||
| } | ||
|
|
||
| echo "IPv4 literal\n"; | ||
| probe('http://127.0.0.1:1/'); | ||
|
|
||
| echo "\nIPv6 literal\n"; | ||
| probe('http://[::1]:1/'); | ||
|
|
||
| /* An IPv4-mapped IPv6 address reaches IPv4 from an AF_INET6 socket. Both forms | ||
| * normalise to the same string. */ | ||
| echo "\nIPv4-mapped IPv6 address\n"; | ||
| probe('http://[::ffff:127.0.0.1]:1/'); | ||
|
|
||
| echo "\nIPv4-mapped IPv6 address, hexadecimal form\n"; | ||
| probe('http://[::ffff:7f00:1]:1/'); | ||
|
|
||
| echo "Done"; | ||
| ?> | ||
| --EXPECT-- | ||
| IPv4 literal | ||
| string(9) "127.0.0.1" | ||
| int(1) | ||
|
|
||
| IPv6 literal | ||
| string(3) "::1" | ||
| int(1) | ||
|
|
||
| IPv4-mapped IPv6 address | ||
| string(16) "::ffff:127.0.0.1" | ||
| int(1) | ||
|
|
||
| IPv4-mapped IPv6 address, hexadecimal form | ||
| string(16) "::ffff:127.0.0.1" | ||
| int(1) | ||
| Done |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.