]> granicus.if.org Git - curl/commitdiff
James Griffiths' max-redirs fix
authorDaniel Stenberg <daniel@haxx.se>
Tue, 28 Nov 2000 09:05:47 +0000 (09:05 +0000)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 28 Nov 2000 09:05:47 +0000 (09:05 +0000)
lib/highlevel.c
lib/url.c
lib/urldata.h

index dc7acc1304005666f6363bc67c8403b613fdd9f0..b3bb9e157796333decbeb56087f059d75bcb9463 100644 (file)
@@ -624,11 +624,17 @@ CURLcode curl_transfer(CURL *curl)
 
       if((res == CURLE_OK) && data->newurl) {
         /* Location: redirect
-
            This is assumed to happen for HTTP(S) only!
-         */
+        */
         char prot[16];
         char path[URL_MAX_LENGTH];
+       if (data->maxredirs && (data->followlocation >= data->maxredirs)) {
+         failf(data,"Maximum (%d) redirects followed", data->maxredirs);
+          curl_disconnect(c_connect);
+          res=CURLE_TOO_MANY_REDIRECTS;
+         break;
+       }
 
         /* mark the next request as a followed location: */
         data->bits.this_is_a_follow = TRUE;
index 9522034f0f389e683e503737bcfb64553d6e4391..2d88aa495f9bbaaf207319c54a880dc389b42ae1 100644 (file)
--- a/lib/url.c
+++ b/lib/url.c
@@ -478,6 +478,9 @@ CURLcode curl_setopt(CURL *curl, CURLoption option, ...)
   case CURLOPT_TIMEOUT:
     data->timeout = va_arg(param, long);
     break;
+  case CURLOPT_MAXREDIRS:
+    data->maxredirs = va_arg(param, long);
+    break;
   case CURLOPT_USERAGENT:
     data->useragent = va_arg(param, char *);
     break;
index a0df9b4ffc01045ddcea382da79b72f5d99a20d8..45b632bbfecd0baeb65df7af6958be5977956aa8 100644 (file)
@@ -417,6 +417,7 @@ struct UrlData {
   /* stuff related to HTTP */
 
   long followlocation;
+  long maxredirs; /* maximum no. of http(s) redirects to follow */
   char *referer;
   bool free_referer; /* set TRUE if 'referer' points to a string we
                         allocated */