CURLINFO_HTTPAUTH_USED.md (1786B)
1 --- 2 c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3 SPDX-License-Identifier: curl 4 Title: CURLINFO_HTTPAUTH_USED 5 Section: 3 6 Source: libcurl 7 See-also: 8 - CURLINFO_PROXYAUTH_USED (3) 9 - CURLINFO_HTTPAUTH_AVAIL (3) 10 - CURLOPT_HTTPAUTH (3) 11 Protocol: 12 - HTTP 13 Added-in: 8.12.0 14 --- 15 16 # NAME 17 18 CURLINFO_HTTPAUTH_USED - get used HTTP authentication method 19 20 # SYNOPSIS 21 22 ~~~c 23 #include <curl/curl.h> 24 25 CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_HTTPAUTH_USED, long *authp); 26 ~~~ 27 28 # DESCRIPTION 29 30 Pass a pointer to a long to receive a bitmask indicating the authentication 31 method that was used in the previous HTTP request. The meaning of the possible 32 bits is explained in the CURLOPT_HTTPAUTH(3) option for curl_easy_setopt(3). 33 34 The returned value has zero or one bit set. 35 36 # %PROTOCOLS% 37 38 # EXAMPLE 39 40 ~~~c 41 int main(void) 42 { 43 CURL *curl = curl_easy_init(); 44 if(curl) { 45 CURLcode res; 46 curl_easy_setopt(curl, CURLOPT_URL, "https://example.com"); 47 curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC | CURLAUTH_DIGEST); 48 curl_easy_setopt(curl, CURLOPT_USERNAME, "shrek"); 49 curl_easy_setopt(curl, CURLOPT_PASSWORD, "swamp"); 50 51 res = curl_easy_perform(curl); 52 53 if(!res) { 54 long auth; 55 res = curl_easy_getinfo(curl, CURLINFO_HTTPAUTH_USED, &auth); 56 if(!res) { 57 if(!auth) 58 printf("No auth used\n"); 59 else { 60 if(auth == CURLAUTH_DIGEST) 61 printf("Used Digest authentication\n"); 62 else 63 printf("Used Basic authentication\n"); 64 } 65 } 66 } 67 curl_easy_cleanup(curl); 68 } 69 } 70 ~~~ 71 72 # %AVAILABILITY% 73 74 # RETURN VALUE 75 76 curl_easy_getinfo(3) returns a CURLcode indicating success or error. 77 78 CURLE_OK (0) means everything was OK, non-zero means an error occurred, see 79 libcurl-errors(3).