mirror of
https://github.com/curl/curl.git
synced 2026-08-03 03:50:28 +03:00
getinfo: provide info which auth was used for HTTP and proxy
CURLINFO_HTTPAUTH_USED and CURLINFO_PROXYAUTH_USED Tested in 590 and 694 Ref: #12668 Idea-by: Ganesh Viswanathan Closes #15450
This commit is contained in:
parent
f3efab1bb4
commit
9d5ecc9613
15 changed files with 409 additions and 9 deletions
|
|
@ -146,6 +146,10 @@ Number of bytes of all headers received. See CURLINFO_HEADER_SIZE(3)
|
|||
|
||||
Available HTTP authentication methods. See CURLINFO_HTTPAUTH_AVAIL(3)
|
||||
|
||||
## CURLINFO_HTTPAUTH_USED
|
||||
|
||||
Used HTTP authentication method. See CURLINFO_HTTPAUTH_USED(3)
|
||||
|
||||
## CURLINFO_HTTP_CONNECTCODE
|
||||
|
||||
Last proxy CONNECT response code. See CURLINFO_HTTP_CONNECTCODE(3)
|
||||
|
|
@ -225,6 +229,10 @@ CURLINFO_PROTOCOL(3)
|
|||
|
||||
Available HTTP proxy authentication methods. See CURLINFO_PROXYAUTH_AVAIL(3)
|
||||
|
||||
## CURLINFO_PROXYAUTH_USED
|
||||
|
||||
Used HTTP proxy authentication methods. See CURLINFO_PROXYAUTH_USED(3)
|
||||
|
||||
## CURLINFO_PROXY_ERROR
|
||||
|
||||
Detailed proxy error. See CURLINFO_PROXY_ERROR(3)
|
||||
|
|
|
|||
76
docs/libcurl/opts/CURLINFO_HTTPAUTH_USED.md
Normal file
76
docs/libcurl/opts/CURLINFO_HTTPAUTH_USED.md
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
---
|
||||
c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
SPDX-License-Identifier: curl
|
||||
Title: CURLINFO_HTTPAUTH_USED
|
||||
Section: 3
|
||||
Source: libcurl
|
||||
See-also:
|
||||
- CURLINFO_PROXYAUTH_USED (3)
|
||||
- CURLINFO_HTTPAUTH_AVAIL (3)
|
||||
- CURLOPT_HTTPAUTH (3)
|
||||
Protocol:
|
||||
- HTTP
|
||||
Added-in: 8.12.0
|
||||
---
|
||||
|
||||
# NAME
|
||||
|
||||
CURLINFO_HTTPAUTH_USED - get used HTTP authentication method
|
||||
|
||||
# SYNOPSIS
|
||||
|
||||
~~~c
|
||||
#include <curl/curl.h>
|
||||
|
||||
CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_HTTPAUTH_USED, long *authp);
|
||||
~~~
|
||||
|
||||
# DESCRIPTION
|
||||
|
||||
Pass a pointer to a long to receive a bitmask indicating the authentication
|
||||
method that was used in the previous HTTP request. The meaning of the possible
|
||||
bits is explained in the CURLOPT_HTTPAUTH(3) option for curl_easy_setopt(3).
|
||||
|
||||
The returned value has zero or one bit set.
|
||||
|
||||
# %PROTOCOLS%
|
||||
|
||||
# EXAMPLE
|
||||
|
||||
~~~c
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
CURLcode res;
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
|
||||
curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC | CURLAUTH_DIGEST);
|
||||
curl_easy_setopt(curl, CURLOPT_USERNAME, "shrek");
|
||||
curl_easy_setopt(curl, CURLOPT_PASSWORD, "swamp");
|
||||
|
||||
res = curl_easy_perform(curl);
|
||||
|
||||
if(!res) {
|
||||
long auth;
|
||||
res = curl_easy_getinfo(curl, CURLINFO_HTTPAUTH_USED, &auth);
|
||||
if(!res) {
|
||||
if(!auth)
|
||||
printf("No auth used\n");
|
||||
else {
|
||||
if(auth == CURLAUTH_DIGEST)
|
||||
printf("Used Digest authentication\n");
|
||||
else
|
||||
printf("Used Basic authentication\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
}
|
||||
~~~
|
||||
|
||||
# %AVAILABILITY%
|
||||
|
||||
# RETURN VALUE
|
||||
|
||||
Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.
|
||||
79
docs/libcurl/opts/CURLINFO_PROXYAUTH_USED.md
Normal file
79
docs/libcurl/opts/CURLINFO_PROXYAUTH_USED.md
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
---
|
||||
c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
SPDX-License-Identifier: curl
|
||||
Title: CURLINFO_PROXYAUTH_USED
|
||||
Section: 3
|
||||
Source: libcurl
|
||||
See-also:
|
||||
- CURLINFO_HTTPAUTH_USED (3)
|
||||
- CURLINFO_PROXYAUTH_AVAIL (3)
|
||||
- CURLOPT_HTTPAUTH (3)
|
||||
Protocol:
|
||||
- HTTP
|
||||
Added-in: 8.12.0
|
||||
---
|
||||
|
||||
# NAME
|
||||
|
||||
CURLINFO_PROXYAUTH_USED - get used HTTP proxy authentication method
|
||||
|
||||
# SYNOPSIS
|
||||
|
||||
~~~c
|
||||
#include <curl/curl.h>
|
||||
|
||||
CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_PROXYAUTH_USED, long *authp);
|
||||
~~~
|
||||
|
||||
# DESCRIPTION
|
||||
|
||||
Pass a pointer to a long to receive a bitmask indicating the authentication
|
||||
method that was used in the previous request done over an HTTP proxy. The
|
||||
meaning of the possible bits is explained in the CURLOPT_HTTPAUTH(3) option
|
||||
for curl_easy_setopt(3).
|
||||
|
||||
The returned value has zero or one bit set.
|
||||
|
||||
# %PROTOCOLS%
|
||||
|
||||
# EXAMPLE
|
||||
|
||||
~~~c
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
CURLcode res;
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
|
||||
curl_easy_setopt(curl, CURLOPT_PROXY, "http://proxy.example.com");
|
||||
curl_easy_setopt(curl, CURLOPT_PROXYAUTH,
|
||||
CURLAUTH_BASIC | CURLAUTH_DIGEST);
|
||||
curl_easy_setopt(curl, CURLOPT_PROXYUSERNAME, "shrek");
|
||||
curl_easy_setopt(curl, CURLOPT_PROXYPASSWORD, "swamp");
|
||||
|
||||
res = curl_easy_perform(curl);
|
||||
|
||||
if(!res) {
|
||||
long auth;
|
||||
res = curl_easy_getinfo(curl, CURLINFO_PROXYAUTH_USED, &auth);
|
||||
if(!res) {
|
||||
if(!auth)
|
||||
printf("No auth used\n");
|
||||
else {
|
||||
if(auth == CURLAUTH_DIGEST)
|
||||
printf("Used Digest proxy authentication\n");
|
||||
else
|
||||
printf("Used Basic proxy authentication\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
}
|
||||
~~~
|
||||
|
||||
# %AVAILABILITY%
|
||||
|
||||
# RETURN VALUE
|
||||
|
||||
Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.
|
||||
|
|
@ -50,6 +50,7 @@ man_MANS = \
|
|||
CURLINFO_HTTP_CONNECTCODE.3 \
|
||||
CURLINFO_HTTP_VERSION.3 \
|
||||
CURLINFO_HTTPAUTH_AVAIL.3 \
|
||||
CURLINFO_HTTPAUTH_USED.3 \
|
||||
CURLINFO_LASTSOCKET.3 \
|
||||
CURLINFO_LOCAL_IP.3 \
|
||||
CURLINFO_LOCAL_PORT.3 \
|
||||
|
|
@ -67,6 +68,7 @@ man_MANS = \
|
|||
CURLINFO_PROXY_ERROR.3 \
|
||||
CURLINFO_PROXY_SSL_VERIFYRESULT.3 \
|
||||
CURLINFO_PROXYAUTH_AVAIL.3 \
|
||||
CURLINFO_PROXYAUTH_USED.3 \
|
||||
CURLINFO_QUEUE_TIME_T.3 \
|
||||
CURLINFO_REDIRECT_COUNT.3 \
|
||||
CURLINFO_REDIRECT_TIME.3 \
|
||||
|
|
|
|||
|
|
@ -449,6 +449,7 @@ CURLINFO_HTTP_CODE 7.4.1 7.10.8
|
|||
CURLINFO_HTTP_CONNECTCODE 7.10.7
|
||||
CURLINFO_HTTP_VERSION 7.50.0
|
||||
CURLINFO_HTTPAUTH_AVAIL 7.10.8
|
||||
CURLINFO_HTTPAUTH_USED 8.12.0
|
||||
CURLINFO_LASTONE 7.4.1
|
||||
CURLINFO_LASTSOCKET 7.15.2 7.45.0
|
||||
CURLINFO_LOCAL_IP 7.21.0
|
||||
|
|
@ -471,6 +472,7 @@ CURLINFO_PROTOCOL 7.52.0 7.85.0
|
|||
CURLINFO_PROXY_ERROR 7.73.0
|
||||
CURLINFO_PROXY_SSL_VERIFYRESULT 7.52.0
|
||||
CURLINFO_PROXYAUTH_AVAIL 7.10.8
|
||||
CURLINFO_PROXYAUTH_USED 8.12.0
|
||||
CURLINFO_PTR 7.54.1
|
||||
CURLINFO_QUEUE_TIME_T 8.6.0
|
||||
CURLINFO_REDIRECT_COUNT 7.9.7
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue