xref: /aosp_15_r20/external/curl/docs/libcurl/opts/CURLOPT_MAXREDIRS.md (revision 6236dae45794135f37c4eb022389c904c8b0090d)
1*6236dae4SAndroid Build Coastguard Worker---
2*6236dae4SAndroid Build Coastguard Workerc: Copyright (C) Daniel Stenberg, <[email protected]>, et al.
3*6236dae4SAndroid Build Coastguard WorkerSPDX-License-Identifier: curl
4*6236dae4SAndroid Build Coastguard WorkerTitle: CURLOPT_MAXREDIRS
5*6236dae4SAndroid Build Coastguard WorkerSection: 3
6*6236dae4SAndroid Build Coastguard WorkerSource: libcurl
7*6236dae4SAndroid Build Coastguard WorkerSee-also:
8*6236dae4SAndroid Build Coastguard Worker  - CURLINFO_REDIRECT_COUNT (3)
9*6236dae4SAndroid Build Coastguard Worker  - CURLINFO_REDIRECT_URL (3)
10*6236dae4SAndroid Build Coastguard Worker  - CURLOPT_FOLLOWLOCATION (3)
11*6236dae4SAndroid Build Coastguard WorkerProtocol:
12*6236dae4SAndroid Build Coastguard Worker  - HTTP
13*6236dae4SAndroid Build Coastguard WorkerAdded-in: 7.5
14*6236dae4SAndroid Build Coastguard Worker---
15*6236dae4SAndroid Build Coastguard Worker
16*6236dae4SAndroid Build Coastguard Worker# NAME
17*6236dae4SAndroid Build Coastguard Worker
18*6236dae4SAndroid Build Coastguard WorkerCURLOPT_MAXREDIRS - maximum number of redirects allowed
19*6236dae4SAndroid Build Coastguard Worker
20*6236dae4SAndroid Build Coastguard Worker# SYNOPSIS
21*6236dae4SAndroid Build Coastguard Worker
22*6236dae4SAndroid Build Coastguard Worker~~~c
23*6236dae4SAndroid Build Coastguard Worker#include <curl/curl.h>
24*6236dae4SAndroid Build Coastguard Worker
25*6236dae4SAndroid Build Coastguard WorkerCURLcode curl_easy_setopt(CURL *handle, CURLOPT_MAXREDIRS, long amount);
26*6236dae4SAndroid Build Coastguard Worker~~~
27*6236dae4SAndroid Build Coastguard Worker
28*6236dae4SAndroid Build Coastguard Worker# DESCRIPTION
29*6236dae4SAndroid Build Coastguard Worker
30*6236dae4SAndroid Build Coastguard WorkerPass a long. The set number is the redirection limit *amount*. If that
31*6236dae4SAndroid Build Coastguard Workermany redirections have been followed, the next redirect triggers the error
32*6236dae4SAndroid Build Coastguard Worker(*CURLE_TOO_MANY_REDIRECTS*). This option only makes sense if the
33*6236dae4SAndroid Build Coastguard WorkerCURLOPT_FOLLOWLOCATION(3) is used at the same time.
34*6236dae4SAndroid Build Coastguard Worker
35*6236dae4SAndroid Build Coastguard WorkerSetting the limit to 0 makes libcurl refuse any redirect.
36*6236dae4SAndroid Build Coastguard Worker
37*6236dae4SAndroid Build Coastguard WorkerSet it to -1 for an infinite number of redirects. This allows your application
38*6236dae4SAndroid Build Coastguard Workerto get stuck in never-ending redirect loops.
39*6236dae4SAndroid Build Coastguard Worker
40*6236dae4SAndroid Build Coastguard Worker# DEFAULT
41*6236dae4SAndroid Build Coastguard Worker
42*6236dae4SAndroid Build Coastguard Worker30 (since 8.3.0), it was previously unlimited.
43*6236dae4SAndroid Build Coastguard Worker
44*6236dae4SAndroid Build Coastguard Worker# %PROTOCOLS%
45*6236dae4SAndroid Build Coastguard Worker
46*6236dae4SAndroid Build Coastguard Worker# EXAMPLE
47*6236dae4SAndroid Build Coastguard Worker
48*6236dae4SAndroid Build Coastguard Worker~~~c
49*6236dae4SAndroid Build Coastguard Workerint main(void)
50*6236dae4SAndroid Build Coastguard Worker{
51*6236dae4SAndroid Build Coastguard Worker  CURL *curl = curl_easy_init();
52*6236dae4SAndroid Build Coastguard Worker  if(curl) {
53*6236dae4SAndroid Build Coastguard Worker    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
54*6236dae4SAndroid Build Coastguard Worker
55*6236dae4SAndroid Build Coastguard Worker    /* enable redirect following */
56*6236dae4SAndroid Build Coastguard Worker    curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
57*6236dae4SAndroid Build Coastguard Worker
58*6236dae4SAndroid Build Coastguard Worker    /* allow three redirects */
59*6236dae4SAndroid Build Coastguard Worker    curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 3L);
60*6236dae4SAndroid Build Coastguard Worker
61*6236dae4SAndroid Build Coastguard Worker    /* Perform the request */
62*6236dae4SAndroid Build Coastguard Worker    curl_easy_perform(curl);
63*6236dae4SAndroid Build Coastguard Worker  }
64*6236dae4SAndroid Build Coastguard Worker}
65*6236dae4SAndroid Build Coastguard Worker~~~
66*6236dae4SAndroid Build Coastguard Worker
67*6236dae4SAndroid Build Coastguard Worker# %AVAILABILITY%
68*6236dae4SAndroid Build Coastguard Worker
69*6236dae4SAndroid Build Coastguard Worker# RETURN VALUE
70*6236dae4SAndroid Build Coastguard Worker
71*6236dae4SAndroid Build Coastguard WorkerReturns CURLE_OK if HTTP is supported, and CURLE_UNKNOWN_OPTION if not.
72