diff --git a/httprl.module b/httprl.module
index 36edd12..713919a 100755
--- a/httprl.module
+++ b/httprl.module
@@ -9,6 +9,15 @@ if (!defined('HTTP_REQUEST_TIMEOUT')) {
   define('HTTP_REQUEST_TIMEOUT', -1);
 }
 
+// HTTP_REQUEST_TIMEOUT is defined in http://drupal.org/node/1096890
+if (!defined('HTTP_REQUEST_ALLOWED_REDIRECTS_EXHAUSTED')) {
+  /**
+  * Error code indicating that the request made by drupal_http_request() exceeded
+  * the maximum allowed redirects without reaching the final target.
+  */
+  define('HTTP_REQUEST_ALLOWED_REDIRECTS_EXHAUSTED', 2);
+}
+
 /**
  * @file
  * HTTP Parallel Request Library module.
@@ -647,7 +656,11 @@ function httprl_parse_data(&$result) {
     case 302: // Moved temporarily
     case 307: // Moved temporarily
       $location = $result->headers['location'];
-      if ($result->options['max_redirects']) {
+      if ($result->options['max_redirects'] <= 0) {
+        $result->code = HTTP_REQUEST_ALLOWED_REDIRECTS_EXHAUSTED;
+        $result->error = 'maximum allowed redirects exhausted';
+      }
+      else {
         // Redirect to the new location.
         // TODO: Parse cookies from header and send them in the redirect request.
         $result->options['max_redirects']--;
