-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ext/curl: Add
CURLINFO_{USED_PROXY,HTTPAUTH_USED,PROXYAUTH_USED}
Adds support for `curl_getinfo()` info keys and additional array keys: - [`CURLINFO_USED_PROXY`](https://curl.se/libcurl/c/CURLINFO_USED_PROXY.html) - `libcurl` >= 8.7.9 - Zero if no proxy was used in the previous transfer or a non-zero value if a proxy was used. - [`CURLINFO_HTTPAUTH_USED`](https://github.com/curl/curl/blob/curl-8_12_0/docs/libcurl/opts/CURLINFO_HTTPAUTH_USED.md) - `libcurl` >= 8.7.9 - Bitmask indicating the authentication method that was used in the previous HTTP request. - [`CURLINFO_PROXYAUTH_USED`](https://github.com/curl/curl/blob/curl-8_12_0/docs/libcurl/opts/CURLINFO_PROXYAUTH_USED.md) - `libcurl` >= 8.12.0 - Bitmask indicating the authentication method that was used in the previous request done over an HTTP proxy. ```php curl_getinfo($ch); ``` ```php [ // ... "used_proxy" => 0, "httpauth_used" => 0, "proxyauth_used" => 0, ] ``` Because the built-in server ext/curl tests use does not support HTTP authentication, there is an online test that uses httpbin. It will be skipped by default unless online tests are run.
- Loading branch information
Showing
8 changed files
with
198 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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 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 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
33 changes: 33 additions & 0 deletions
33
ext/curl/tests/curl_getinfo_CURLINFO_HTTPAUTH_USED-online.phpt
This file contains 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,33 @@ | ||
--TEST-- | ||
curl_getinfo - CURLINFO_HTTPAUTH_USED - online test | ||
--EXTENSIONS-- | ||
curl | ||
--SKIPIF-- | ||
<?php | ||
$curl_version = curl_version(); | ||
if ($curl_version['version_number'] < 0x080c00) die("skip: test works only with curl >= 8.12.0"); | ||
if (getenv("SKIP_ONLINE_TESTS")) die('skip online test'); | ||
?> | ||
--FILE-- | ||
<?php | ||
|
||
$ch = curl_init(); | ||
curl_setopt($ch, CURLOPT_URL, "https://httpbin.org/basic-auth/foo/bar"); | ||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | ||
|
||
$info = curl_getinfo($ch); | ||
var_dump($info['httpauth_used'] === 0); // this is always 0 before executing the transfer | ||
|
||
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC | CURLAUTH_DIGEST); | ||
curl_setopt($ch, CURLOPT_USERNAME, "foo"); | ||
curl_setopt($ch, CURLOPT_PASSWORD, "bar"); | ||
|
||
$result = curl_exec($ch); | ||
$info = curl_getinfo($ch); | ||
|
||
var_dump($info['httpauth_used'] === CURLAUTH_BASIC); | ||
|
||
?> | ||
--EXPECT-- | ||
bool(true) | ||
bool(true) |
This file contains 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,66 @@ | ||
--TEST-- | ||
curl_getinfo - CURLINFO_HTTPAUTH_USED | ||
--EXTENSIONS-- | ||
curl | ||
--SKIPIF-- | ||
<?php | ||
$curl_version = curl_version(); | ||
if ($curl_version['version_number'] < 0x080c00) die("skip: test works only with curl >= 8.12.0"); | ||
?> | ||
--FILE-- | ||
<?php | ||
include 'server.inc'; | ||
|
||
$host = curl_cli_server_start(); | ||
$port = (int) (explode(':', $host))[1]; | ||
|
||
$ch = curl_init(); | ||
curl_setopt($ch, CURLOPT_URL, "{$host}/get.inc?test=file"); | ||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | ||
|
||
echo "httpauth_used and proxyauth_used empty\n"; | ||
|
||
$info = curl_getinfo($ch); | ||
var_dump(isset($info['httpauth_used'])); | ||
var_dump(isset($info['proxyauth_used'])); | ||
var_dump($info['httpauth_used'] === 0); // this is always 0 before executing the transfer | ||
var_dump($info['proxyauth_used'] === 0); // this is always 0 before executing the transfer | ||
|
||
$result = curl_exec($ch); | ||
echo "httpauth_used and proxyauth_used empty after request\n"; | ||
$info = curl_getinfo($ch); | ||
var_dump(isset($info['httpauth_used'])); | ||
var_dump(isset($info['proxyauth_used'])); | ||
var_dump($info['httpauth_used'] === 0); | ||
var_dump($info['proxyauth_used'] === 0); | ||
var_dump(curl_getinfo($ch, CURLINFO_HTTPAUTH_USED) === $info['used_proxy']); | ||
var_dump(curl_getinfo($ch, CURLINFO_PROXYAUTH_USED) === $info['proxyauth_used']); | ||
|
||
echo "httpauth_used set after request\n"; | ||
|
||
$ch = curl_init(); | ||
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC | CURLAUTH_DIGEST); | ||
curl_setopt($ch, CURLOPT_USERNAME, "foo"); | ||
curl_setopt($ch, CURLOPT_PASSWORD, "bar"); | ||
|
||
$result = curl_exec($ch); | ||
$info = curl_getinfo($ch); | ||
|
||
var_dump($info['httpauth_used']); // Built-in server does not support auth | ||
|
||
?> | ||
--EXPECT-- | ||
httpauth_used and proxyauth_used empty | ||
bool(true) | ||
bool(true) | ||
bool(true) | ||
bool(true) | ||
httpauth_used and proxyauth_used empty after request | ||
bool(true) | ||
bool(true) | ||
bool(true) | ||
bool(true) | ||
bool(true) | ||
bool(true) | ||
httpauth_used set after request | ||
int(0) |
This file contains 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,38 @@ | ||
--TEST-- | ||
curl_getinfo - CURLINFO_USED_PROXY | ||
--EXTENSIONS-- | ||
curl | ||
--SKIPIF-- | ||
<?php | ||
$curl_version = curl_version(); | ||
if ($curl_version['version_number'] < 0x080700) die("skip: test works only with curl >= 8.7.0"); | ||
?> | ||
--FILE-- | ||
<?php | ||
include 'server.inc'; | ||
|
||
$host = curl_cli_server_start(); | ||
$port = (int) (explode(':', $host))[1]; | ||
|
||
$ch = curl_init(); | ||
curl_setopt($ch, CURLOPT_URL, "{$host}/get.inc?test=file"); | ||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | ||
|
||
$info = curl_getinfo($ch); | ||
var_dump(isset($info['used_proxy'])); | ||
var_dump($info['used_proxy'] === 0); // this is always 0 before executing the transfer | ||
|
||
$result = curl_exec($ch); | ||
|
||
$info = curl_getinfo($ch); | ||
var_dump(isset($info['used_proxy'])); | ||
var_dump($info['used_proxy'] === 0); | ||
var_dump(curl_getinfo($ch, CURLINFO_USED_PROXY) === $info['used_proxy']); | ||
|
||
?> | ||
--EXPECT-- | ||
bool(true) | ||
bool(true) | ||
bool(true) | ||
bool(true) | ||
bool(true) |