                 endCredential = NSURLCredential(user: credential.0, password: credential.1, persistence: .ForSession)
             }
         }
-        
+
         completionHandler(disposition, endCredential)
     }
-}+
+    public func URLSession(session: NSURLSession, task: NSURLSessionTask, willPerformHTTPRedirection response: NSHTTPURLResponse, newRequest request: NSURLRequest, completionHandler: (NSURLRequest!) -> Void) {
+        if let allowRedirects = taskConfigs[task.taskIdentifier]?.redirects {
+            if !allowRedirects {
+                completionHandler(nil)
+                return
+            }
+            completionHandler(request)
+        }
+        completionHandler(request)
+    }
+}

    }
}

public class Requests:NSObject, NSURLSessionDelegate, NSURLSessionTaskDelegate {

    class var shared: Requests {

    }

    var credentials:[Int:(String,String)]=[:]
    var taskConfigs:[TaskID:TaskConfiguration]=[:]

    var session: NSURLSession!
    var invalidURLError = NSError(domain: "requests.swift", code: 0, userInfo: [NSLocalizedDescriptionKey:"[Requests] URL is invalid"])
    var syncResultAccessError = NSError(domain: "requests.swift", code: 1, userInfo: [NSLocalizedDescriptionKey:"[Requests] You are accessing asynchronous result synchronously."])
