@@ -56,9 +56,7 @@ internal final class _EasyHandle {
5656 fileprivate var headerList : _CurlStringList ?
5757 fileprivate var pauseState : _PauseState = [ ]
5858 internal var timeoutTimer : _TimeoutSource !
59- #if os(Android)
60- static fileprivate var _CAInfoFile : UnsafeMutablePointer < Int8 > ?
61- #endif
59+ private var errorBuffer = [ UInt8] ( repeating: 0 , count: 1000 )
6260
6361 init ( delegate: _EasyHandleDelegate ) {
6462 self . delegate = delegate
@@ -89,8 +87,8 @@ extension _EasyHandle {
8987}
9088
9189internal extension _EasyHandle {
92- func completedTransfer( withErrorCode errorCode : Int ? ) {
93- delegate? . transferCompleted ( withErrorCode : errorCode )
90+ func completedTransfer( withErrorInfo errorInfo : URLErrorInfo ? ) {
91+ delegate? . transferCompleted ( withErrorInfo : errorInfo )
9492 }
9593}
9694internal protocol _EasyHandleDelegate : class {
@@ -107,7 +105,7 @@ internal protocol _EasyHandleDelegate: class {
107105 func fill( writeBuffer buffer: UnsafeMutableBufferPointer < Int8 > ) -> _EasyHandle . _WriteBufferResult
108106 /// The transfer for this handle completed.
109107 /// - parameter errorCode: An NSURLError code, or `nil` if no error occured.
110- func transferCompleted( withErrorCode errorCode : Int ? )
108+ func transferCompleted( withErrorInfo errorInfo : URLErrorInfo ? )
111109 /// Seek the input stream to the given position
112110 func seekInputStream( to position: UInt64 ) throws
113111 /// Gets called during the transfer to update progress.
@@ -170,20 +168,23 @@ extension _EasyHandle {
170168 let protocols = ( CFURLSessionProtocolHTTP | CFURLSessionProtocolHTTPS)
171169 try ! CFURLSession_easy_setopt_long ( rawHandle, CFURLSessionOptionPROTOCOLS, protocols) . asError ( )
172170 try ! CFURLSession_easy_setopt_long ( rawHandle, CFURLSessionOptionREDIR_PROTOCOLS, protocols) . asError ( )
173- #if os(Android)
174- // See https://curl.haxx.se/docs/sslcerts.html
175- // For SSL to work you need "cacert.pem" to be accessable
176- // at the path pointed to by the URLSessionCAInfo env var.
177- // Downloadable here: https://curl.haxx.se/ca/cacert.pem
178- if let caInfo = _EasyHandle. _CAInfoFile {
179- if String ( cString: caInfo) == " UNSAFE_SSL_NOVERIFY " {
180- try ! CFURLSession_easy_setopt_int ( rawHandle, CFURLSessionOptionSSL_VERIFYPEER, 0 ) . asError ( )
181- }
182- else {
183- try ! CFURLSession_easy_setopt_ptr ( rawHandle, CFURLSessionOptionCAINFO, caInfo) . asError ( )
184- }
171+ errorBuffer. withUnsafeMutableBufferPointer {
172+ try ! CFURLSession_easy_setopt_ptr ( rawHandle, CFURLSessionOptionERRORBUFFER, $0. baseAddress) . asError ( )
173+ }
174+ #if os(Android)
175+ // See https://curl.haxx.se/docs/sslcerts.html
176+ // For SSL on Android you need a "cacert.pem" to be
177+ // accessible at the path pointed to by this env var.
178+ // Downloadable here: https://curl.haxx.se/ca/cacert.pem
179+ if let caInfo = getenv ( " URLSessionCertificateAuthorityInfoFile " ) {
180+ if String ( cString: caInfo) == " INSECURE_SSL_NO_VERIFY " {
181+ try ! CFURLSession_easy_setopt_long ( rawHandle, CFURLSessionOptionSSL_VERIFYPEER, 0 ) . asError ( )
185182 }
186- #endif
183+ else {
184+ try ! CFURLSession_easy_setopt_ptr ( rawHandle, CFURLSessionOptionCAINFO, caInfo) . asError ( )
185+ }
186+ }
187+ #endif
187188 //TODO: Added in libcurl 7.45.0
188189 //TODO: Set default protocol for schemeless URLs
189190 //CURLOPT_DEFAULT_PROTOCOL available only in libcurl 7.45.0
@@ -630,19 +631,6 @@ extension _EasyHandle._CurlStringList {
630631 }
631632}
632633
633- #if os(Android)
634- extension URLSession {
635-
636- public static func setCAInfoFile( _ _CAInfoFile: String ) {
637- free ( _EasyHandle. _CAInfoFile)
638- _CAInfoFile. withCString {
639- _EasyHandle. _CAInfoFile = strdup ( $0)
640- }
641- }
642-
643- }
644- #endif
645-
646634extension CFURLSessionEasyCode : Equatable {
647635 public static func == ( lhs: CFURLSessionEasyCode , rhs: CFURLSessionEasyCode ) -> Bool {
648636 return lhs. value == rhs. value
0 commit comments