Merge pull request #884 from nethraravindran/nsurlsession-branch
diff --git a/Foundation/NSURLSession/EasyHandle.swift b/Foundation/NSURLSession/EasyHandle.swift
index dbc8ec7..e3782e9 100644
--- a/Foundation/NSURLSession/EasyHandle.swift
+++ b/Foundation/NSURLSession/EasyHandle.swift
@@ -167,9 +167,8 @@
try! CFURLSession_easy_setopt_long(rawHandle, CFURLSessionOptionPROTOCOLS, protocols).asError()
try! CFURLSession_easy_setopt_long(rawHandle, CFURLSessionOptionREDIR_PROTOCOLS, protocols).asError()
//TODO: Added in libcurl 7.45.0
- // "https".withCString {
- // try! CFURLSession_easy_setopt_ptr(rawHandle, CFURLSessionOptionDEFAULT_PROTOCOL, UnsafeMutablePointer($0)).asError()
- //}
+ //TODO: Set default protocol for schemeless URLs
+ //CURLOPT_DEFAULT_PROTOCOL available only in libcurl 7.45.0
}
//TODO: Proxy setting, namely CFURLSessionOptionPROXY, CFURLSessionOptionPROXYPORT,
@@ -189,27 +188,21 @@
// We need to retain the list for as long as the rawHandle is in use.
headerList = list
}
- /// Wait for pipelining/multiplexing
+ ///TODO: Wait for pipelining/multiplexing. Unavailable on Ubuntu 14.0
/// - SeeAlso: https://curl.haxx.se/libcurl/c/CURLOPT_PIPEWAIT.html
- //func set(waitForPipeliningAndMultiplexing flag: Bool) {
- // try! CFURLSession_easy_setopt_long(rawHandle, CFURLSessionOptionPIPEWAIT, flag ? 1 : 0).asError()
- //}
//TODO: The public API does not allow us to use CFURLSessionOptionSTREAM_DEPENDS / CFURLSessionOptionSTREAM_DEPENDS_E
// Might be good to add support for it, though.
- /// set numerical stream weight
+ ///TODO: Set numerical stream weight when CURLOPT_PIPEWAIT is enabled
/// - Parameter weight: values are clamped to lie between 0 and 1
/// - SeeAlso: https://curl.haxx.se/libcurl/c/CURLOPT_STREAM_WEIGHT.html
/// - SeeAlso: http://httpwg.org/specs/rfc7540.html#StreamPriority
- //func set(streamWeight weight: Float) {
- // // Scale and clamp such that the range 0->1 ends up 1->256
- // let w = 1 + max(0, min(255, Int(round(weight * 255))))
- // try! CFURLSession_easy_setopt_long(rawHandle, CFURLSessionOptionPIPEWAIT, w).asError()
- //}
+
/// Enable automatic decompression of HTTP downloads
/// - SeeAlso: https://curl.haxx.se/libcurl/c/CURLOPT_ACCEPT_ENCODING.html
/// - SeeAlso: https://curl.haxx.se/libcurl/c/CURLOPT_HTTP_CONTENT_DECODING.html
+
func set(automaticBodyDecompression flag: Bool) {
if flag {
"".withCString {
diff --git a/Foundation/NSURLSession/HTTPBodySource.swift b/Foundation/NSURLSession/HTTPBodySource.swift
index 1089a2e..2dc7120 100644
--- a/Foundation/NSURLSession/HTTPBodySource.swift
+++ b/Foundation/NSURLSession/HTTPBodySource.swift
@@ -37,10 +37,6 @@
/// Split `dispatch_data_t` into `(head, tail)` pair.
internal func splitData(dispatchData data: DispatchData, atPosition position: Int) -> (DispatchData,DispatchData) {
- /*let length = dispatch_data_get_size(data)
- let head = dispatch_data_create_subrange(data, 0, position)
- let tail = dispatch_data_create_subrange(data, position, length - position)
- return (head, tail)*/
return (data.subdata(in: 0..<position), data.subdata(in: position..<data.count))
}
diff --git a/Foundation/NSURLSession/MultiHandle.swift b/Foundation/NSURLSession/MultiHandle.swift
index d6bbb24..b6d5008 100644
--- a/Foundation/NSURLSession/MultiHandle.swift
+++ b/Foundation/NSURLSession/MultiHandle.swift
@@ -36,13 +36,11 @@
internal final class _MultiHandle {
let rawHandle = CFURLSessionMultiHandleInit()
let queue: DispatchQueue
- //let queue = DispatchQueue(label: "MultiHandle.isolation", attributes: .serial)
let group = DispatchGroup()
fileprivate var easyHandles: [_EasyHandle] = []
fileprivate var timeoutSource: _TimeoutSource? = nil
init(configuration: URLSession._Configuration, workQueue: DispatchQueue) {
- //queue.setTarget(queue: workQueue)
queue = DispatchQueue(label: "MultiHandle.isolation", target: workQueue)
setupCallbacks()
configure(with: configuration)
@@ -311,7 +309,6 @@
self.rawSource = DispatchSource.makeTimerSource(queue: queue) as! DispatchSource
let delay = UInt64(max(1, milliseconds - 1))
- //let leeway: UInt64 = (milliseconds == 1) ? NSEC_PER_USEC : NSEC_PER_MSEC
let start = DispatchTime.now() + DispatchTimeInterval.milliseconds(Int(delay))
rawSource.scheduleRepeating(deadline: start, interval: .milliseconds(Int(delay)), leeway: (milliseconds == 1) ? .microseconds(Int(1)) : .milliseconds(Int(1)))
diff --git a/Foundation/NSURLSession/NSURLSession.swift b/Foundation/NSURLSession/NSURLSession.swift
index 4356ad7..4874bf3 100644
--- a/Foundation/NSURLSession/NSURLSession.swift
+++ b/Foundation/NSURLSession/NSURLSession.swift
@@ -174,8 +174,7 @@
fileprivate var sessionCounter = Int32(0)
fileprivate func nextSessionIdentifier() -> Int32 {
- //TODO: find an alternative for this on Linux
- //return OSAtomicIncrement32Barrier(&sessionCounter)
+ //TODO: find an alternative for OSAtomicIncrement32Barrier() on Linux
sessionCounter += 1
return sessionCounter
}
diff --git a/Foundation/NSURLSession/NSURLSessionTask.swift b/Foundation/NSURLSession/NSURLSessionTask.swift
index 5856d5d..bc46497 100644
--- a/Foundation/NSURLSession/NSURLSessionTask.swift
+++ b/Foundation/NSURLSession/NSURLSessionTask.swift
@@ -116,11 +116,7 @@
self.easyHandle = _EasyHandle(delegate: self)
}
deinit {
- //TODO: Can we ensure this somewhere else? This might run on the wrong
- // thread / queue.
- //if internalState.isEasyHandleAddedToMultiHandle {
- // session.removeHandle(easyHandle)
- //}
+ //TODO: Do we remove the EasyHandle from the session here? This might run on the wrong thread / queue.
}
open override func copy() -> Any {
@@ -560,10 +556,8 @@
easyHandle.set(followLocation: false)
easyHandle.set(customHeaders: curlHeaders(for: request))
- //Options unavailable on Ubuntu 14.04 (libcurl 7.36)
- //TODO: Introduce something like an #if
- //easyHandle.set(waitForPipeliningAndMultiplexing: true)
- //easyHandle.set(streamWeight: priority)
+ //TODO: The CURLOPT_PIPEDWAIT option is unavailable on Ubuntu 14.04 (libcurl 7.36)
+ //TODO: Introduce something like an #if, if we want to set them here
//set the request timeout
//TODO: the timeout value needs to be reset on every data transfer
@@ -933,8 +927,6 @@
//TODO: Should the `public response: URLResponse` property be updated
// before we call delegate API
- // `func urlSession(session: session: URLSession, task: URLSessionTask, willPerformHTTPRedirection response: NSHTTPURLResponse, newRequest request: NSURLRequest, completionHandler: (NSURLRequest?) -> Void)`
- // ?
internalState = .waitingForRedirectCompletionHandler(response: response, bodyDataDrain: bodyDataDrain)
// We need this ugly cast in order to be able to support `URLSessionTask.init()`