CURLINFO_RETRY_AFTER.md (1870B)
1 --- 2 c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3 SPDX-License-Identifier: curl 4 Title: CURLINFO_RETRY_AFTER 5 Section: 3 6 Source: libcurl 7 See-also: 8 - CURLOPT_HEADERFUNCTION (3) 9 - CURLOPT_STDERR (3) 10 - curl_easy_header (3) 11 Protocol: 12 - All 13 Added-in: 7.66.0 14 --- 15 16 # NAME 17 18 CURLINFO_RETRY_AFTER - returns the Retry-After retry delay 19 20 # SYNOPSIS 21 22 ~~~c 23 #include <curl/curl.h> 24 25 CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_RETRY_AFTER, 26 curl_off_t *retry); 27 ~~~ 28 29 # DESCRIPTION 30 31 Pass a pointer to a curl_off_t variable to receive the number of seconds the 32 HTTP server suggests the client should wait until the next request is 33 issued. The information from the "Retry-After:" header. 34 35 While the HTTP header might contain a fixed date string, the 36 CURLINFO_RETRY_AFTER(3) always returns the number of seconds to wait - 37 or zero if there was no header or the header could not be parsed. 38 39 This option used to return a negative wait time if the server provided a date 40 in the past. Since 8.12.0, a negative wait time is returned as zero. In any 41 case we recommend checking that the wait time is within an acceptable range for 42 your circumstance. 43 44 # DEFAULT 45 46 Zero if there was no header. 47 48 # %PROTOCOLS% 49 50 # EXAMPLE 51 52 ~~~c 53 int main(void) 54 { 55 CURL *curl = curl_easy_init(); 56 if(curl) { 57 CURLcode res; 58 curl_easy_setopt(curl, CURLOPT_URL, "https://example.com"); 59 res = curl_easy_perform(curl); 60 if(res == CURLE_OK) { 61 curl_off_t wait = 0; 62 curl_easy_getinfo(curl, CURLINFO_RETRY_AFTER, &wait); 63 if(wait) 64 printf("Wait for %" CURL_FORMAT_CURL_OFF_T " seconds\n", wait); 65 } 66 curl_easy_cleanup(curl); 67 } 68 } 69 ~~~ 70 71 # %AVAILABILITY% 72 73 # RETURN VALUE 74 75 curl_easy_getinfo(3) returns a CURLcode indicating success or error. 76 77 CURLE_OK (0) means everything was OK, non-zero means an error occurred, see 78 libcurl-errors(3).