         return task
     }
 
-    public func cancelRequest<T: RequestType>(requestType: T.Type, passingTest test: T -> Bool = { r in true }) {
+    /// Cancels requests that passes the test.
+    /// - parameter requestType: The request type to cancel.
+    /// - parameter test: The test closure that determines if a request should be cancelled or not.
+    public func cancelRequest<Request: RequestType>(requestType: Request.Type, passingTest test: Request -> Bool = { r in true }) {
         adapter.getTasksWithHandler { [weak self] tasks in
-            tasks
+            return tasks
                 .filter { task in
-                    if let request = self?.requestForTask(task) as T? {
+                    if let request = self?.requestForTask(task) as Request? {
                         return test(request)
                     } else {
                         return false


private var taskRequestKey = 0

public class Session {
    public let adapter: SessionAdapterType

    public init(adapter: SessionAdapterType) {
        self.adapter = adapter
    }

    // Shared session for static methods
    public static var sharedSession: Session = {
        let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
        let adapter = NSURLSessionAdapter(configuration: configuration)
        return Session(adapter: adapter)
    }()

    public static func sendRequest<T: RequestType>(request: T, handler: (Result<T.Response, SessionTaskError>) -> Void = {r in}) -> SessionTaskType? {
        return sharedSession.sendRequest(request, handler: handler)
    }
    
    public static func cancelRequest<T: RequestType>(requestType: T.Type, passingTest test: T -> Bool = { r in true }) {
        sharedSession.cancelRequest(requestType, passingTest: test)
    }

    public func sendRequest<T: RequestType>(request: T, handler: (Result<T.Response, SessionTaskError>) -> Void = {r in}) -> SessionTaskType? {
        let URLRequest: NSURLRequest
        do {
            URLRequest = try request.buildURLRequest()

        }

        let task = adapter.resumedTaskWithURLRequest(URLRequest) { data, URLResponse, error in
            let result: Result<Request.Response, SessionTaskError>

            switch (data, URLResponse, error) {
            case (_, _, let error?):
