 }
 
 private var dataTaskResponseBufferKey = 0
+private var uploadTaskInputStreamKey = 0
 private var taskAssociatedObjectCompletionHandlerKey = 0
 
 /// `NSURLSessionAdapter` connects `NSURLSession` with `Session`.

/// delegate methods that you want to implement. Since `NSURLSessionAdapter` also implements delegate methods
/// `URLSession(_:task: didCompleteWithError:)` and `URLSession(_:dataTask:didReceiveData:)`, you have to call
/// `super` in these methods if you implement them.
public class NSURLSessionAdapter: NSObject, SessionAdapterType, NSURLSessionDelegate {
    /// The undelying `NSURLSession` instance.
    public var URLSession: NSURLSession!
    

            URLRequest.setValue(value, forHTTPHeaderField: key)
        }

        let task: NSURLSessionTask
        switch try request.bodyParameters?.buildEntity() {
        case .Data(let data)?:
            task = URLSession.uploadTaskWithRequest(URLRequest, fromData: data)

        case .InputStream(let inputStream)?:
            task = URLSession.uploadTaskWithStreamedRequest(URLRequest)
            setInputStream(inputStream, forTask: task)

        default:
            task = URLSession.dataTaskWithRequest(URLRequest)
        }

        setBuffer(NSMutableData(), forTask: task)
        setHandler(handler, forTask: task)
