From 966fa848a0213be52d3a4b3787c36ec7c5553f22 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 27 Oct 2005 22:05:38 +0000 Subject: Nis Jorgensen filed bug report #1338648 (http://curl.haxx.se/bug/view.cgi?id=1338648) which really is more of a feature request, but anyway. It pointed out that --max-redirs did not allow it to be set to 0, which then would return an error code on the first Location: found. Based on Nis' patch, now libcurl supports CURLOPT_MAXREDIRS set to 0, or -1 for infinity. Added test case 274 to verify. --- CHANGES | 7 ++++++ docs/curl.1 | 3 ++- docs/libcurl/curl_easy_setopt.3 | 6 +++-- lib/transfer.c | 2 +- lib/url.c | 2 +- lib/urldata.h | 3 ++- src/main.c | 7 ++---- tests/data/Makefile.am | 4 +++- tests/data/test274 | 50 +++++++++++++++++++++++++++++++++++++++++ 9 files changed, 72 insertions(+), 12 deletions(-) create mode 100644 tests/data/test274 diff --git a/CHANGES b/CHANGES index 77d3eac4f..9748b662c 100644 --- a/CHANGES +++ b/CHANGES @@ -9,6 +9,13 @@ Daniel (27 October 2005) +- Nis Jorgensen filed bug report #1338648 + (http://curl.haxx.se/bug/view.cgi?id=1338648) which really is more of a + feature request, but anyway. It pointed out that --max-redirs did not allow + it to be set to 0, which then would return an error code on the first + Location: found. Based on Nis' patch, now libcurl supports CURLOPT_MAXREDIRS + set to 0, or -1 for infinity. Added test case 274 to verify. + - tommink[at]post.pl reported in bug report #1337723 (http://curl.haxx.se/bug/view.cgi?id=1337723) that curl could not upload binary data from stdin on Windows if the data contained control-Z (hex 1a) diff --git a/docs/curl.1 b/docs/curl.1 index 8a422b9e2..a42c124b6 100644 --- a/docs/curl.1 +++ b/docs/curl.1 @@ -1127,7 +1127,8 @@ If this option is used several times, the last one will be used. .IP "--max-redirs " Set maximum number of redirection-followings allowed. If \fI-L/--location\fP is used, this option can be used to prevent curl from following redirections -\&"in absurdum". +\&"in absurdum". By default, the limit is set to 50 redirections. Set this +option to -1 to make it limitless. If this option is used several times, the last one will be used. .IP "-0/--http1.0" diff --git a/docs/libcurl/curl_easy_setopt.3 b/docs/libcurl/curl_easy_setopt.3 index 99e57e684..3e49643e9 100644 --- a/docs/libcurl/curl_easy_setopt.3 +++ b/docs/libcurl/curl_easy_setopt.3 @@ -21,7 +21,7 @@ .\" * $Id$ .\" ************************************************************************** .\" -.TH curl_easy_setopt 3 "22 Sep 2005" "libcurl 7.14.2" "libcurl Manual" +.TH curl_easy_setopt 3 "27 Oct 2005" "libcurl 7.14.2" "libcurl Manual" .SH NAME curl_easy_setopt - set options for a curl easy handle .SH SYNOPSIS @@ -516,7 +516,9 @@ option is meaningful only when setting \fICURLOPT_FOLLOWLOCATION\fP. Pass a long. The set number will be the redirection limit. If that many redirections have been followed, the next redirect will cause an error (\fICURLE_TOO_MANY_REDIRECTS\fP). This option only makes sense if the -\fICURLOPT_FOLLOWLOCATION\fP is used at the same time. +\fICURLOPT_FOLLOWLOCATION\fP is used at the same time. Added in 7.15.1: +Setting the limit to 0 will make libcurl refuse any redirect. Set it to -1 for +an infinite number of redirects (which is the default) .IP CURLOPT_PUT A non-zero parameter tells the library to use HTTP PUT to transfer data. The data should be set with \fICURLOPT_READDATA\fP and \fICURLOPT_INFILESIZE\fP. diff --git a/lib/transfer.c b/lib/transfer.c index 13f31e9bc..1706ccb6f 100644 --- a/lib/transfer.c +++ b/lib/transfer.c @@ -1765,7 +1765,7 @@ CURLcode Curl_follow(struct SessionHandle *data, size_t newlen; char *newest; - if (data->set.maxredirs && + if ((data->set.maxredirs != -1) && (data->set.followlocation >= data->set.maxredirs)) { failf(data,"Maximum (%d) redirects followed", data->set.maxredirs); return CURLE_TOO_MANY_REDIRECTS; diff --git a/lib/url.c b/lib/url.c index c4f3fbf3d..bff500f57 100644 --- a/lib/url.c +++ b/lib/url.c @@ -320,7 +320,7 @@ CURLcode Curl_open(struct SessionHandle **curl) data->set.infilesize = -1; /* we don't know any size */ data->set.postfieldsize = -1; - + data->set.maxredirs = -1; /* allow any amount by default */ data->state.current_speed = -1; /* init to negative == impossible */ data->set.httpreq = HTTPREQ_GET; /* Default HTTP request */ diff --git a/lib/urldata.h b/lib/urldata.h index 87a751f6f..b5b2d8040 100644 --- a/lib/urldata.h +++ b/lib/urldata.h @@ -956,7 +956,8 @@ struct UserDefined { char *set_range; /* range, if used. See README for detailed specification on this syntax. */ long followlocation; /* as in HTTP Location: */ - long maxredirs; /* maximum no. of http(s) redirects to follow */ + long maxredirs; /* maximum no. of http(s) redirects to follow, set to -1 + for infinity */ char *set_referer; /* custom string */ bool free_referer; /* set TRUE if 'referer' points to a string we allocated */ diff --git a/src/main.c b/src/main.c index 33200cea0..99edc61d7 100644 --- a/src/main.c +++ b/src/main.c @@ -3211,6 +3211,7 @@ operate(struct Configurable *config, int argc, char *argv[]) config->create_dirs=FALSE; config->lastrecvtime = curlx_tvnow(); config->lastsendtime = curlx_tvnow(); + config->maxredirs = DEFAULT_MAXREDIRS; if(argc>1 && (!curlx_strnequal("--", argv[1], 2) && (argv[1][0] == '-')) && @@ -3803,11 +3804,7 @@ operate(struct Configurable *config, int argc, char *argv[]) curl_easy_setopt(curl, CURLOPT_FILETIME, TRUE); } - if (config->maxredirs) - curl_easy_setopt(curl, CURLOPT_MAXREDIRS, config->maxredirs); - else - curl_easy_setopt(curl, CURLOPT_MAXREDIRS, DEFAULT_MAXREDIRS); - + curl_easy_setopt(curl, CURLOPT_MAXREDIRS, config->maxredirs); curl_easy_setopt(curl, CURLOPT_CRLF, config->crlf); curl_easy_setopt(curl, CURLOPT_QUOTE, config->quote); curl_easy_setopt(curl, CURLOPT_POSTQUOTE, config->postquote); diff --git a/tests/data/Makefile.am b/tests/data/Makefile.am index 5b646ddf9..0711182f0 100644 --- a/tests/data/Makefile.am +++ b/tests/data/Makefile.am @@ -33,4 +33,6 @@ EXTRA_DIST = test1 test108 test117 test127 test20 test27 test34 test46 \ test237 test238 test239 test243 test245 test246 test247 test248 test249 \ test250 test251 test252 test253 test254 test255 test521 test522 test523 \ test256 test257 test258 test259 test260 test261 test262 test263 test264 \ - test265 test266 test267 test268 test269 test270 test271 test272 test273 + test265 test266 test267 test268 test269 test270 test271 test272 test273 \ + test274 + diff --git a/tests/data/test274 b/tests/data/test274 new file mode 100644 index 000000000..4eac4d5fd --- /dev/null +++ b/tests/data/test274 @@ -0,0 +1,50 @@ + + +HTTP +HTTP GET +followlocation +--max-redirs + + +# Server-side + + +HTTP/1.1 301 This is a weirdo text message swsclose +Server: test-server/fake +Location: data/reply/25 +Content-Length: 0 +Connection: close + + + + +# Client-side + + +http + + +HTTP Location: following with --max-redirs 0 + + +http://%HOSTIP:%HTTPPORT/want/274 -L --max-redirs 0 + + + +# Verify data after the test has been "shot" + + +^User-Agent: curl/.* + + +GET /want/274 HTTP/1.1 +User-Agent: curl/7.8.1-pre3 (sparc-sun-solaris2.7) libcurl 7.8.1-pre3 (OpenSSL 0.9.6a) (krb4 enabled) +Host: 127.0.0.1:%HTTPPORT +Accept: */* + + + + +47 + + -- cgit v1.2.3