<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Absolutely on point: I think it would be reasonable to make a new type to handle the interface layer _CFURLSession etc; that way some of the simple interfaces can be kept in C to the libcurl layer.</div><div class=""><br class=""></div><div class="">Testing is very important; however the major consideration I would suggest to take into account is try to keep it as simple as possible. Networking is hard to get right and verification is important. If at all possible eliminate as many variables as you can. It might be reasonable to spawn a small process off to deal with the server side of things if you don’t want to assume the network itself is something that needs to be tested.</div><div class=""><br class=""></div><div class="">As many tests that can be self contained as possible would be best. But it might be safe to assume that <a href="http://swift.org" class="">swift.org</a> is up.</div><div class=""><br class=""></div><br class=""><div><blockquote type="cite" class=""><div class="">On Mar 14, 2016, at 10:29 AM, Robert Stephen Thompson via swift-corelibs-dev <<a href="mailto:swift-corelibs-dev@swift.org" class="">swift-corelibs-dev@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Just a couple of tips based on my experience wrapping libxml2 for NSXMLDocument:<div class="">1. You’ll need to actually import and link libcurl with CoreFoundation instead of trying to make a libcurl module.modulemap and importing it directly. This is because if you do it that way, you’ll have to add libcurl as a dependency _throughout_ the Swift build process, and it would all be pretty disruptive (and difficult to do).</div><div class="">2. As a consequence of 1., you’ll need to wrap every function you call from libcurl in a new CoreFoundation API. See CFXMLInterface.h and CFXMLInterface.c for what I mean. Of course, this also gives you the opportunity to add nullability annotations, wrap things in CFString, CFError, CFArray, etc, so it’s not just busy-work for getting around the build system, heh. Just depends on how much C you want to write, you could just straight wrap the libcurl functions and do everything in Swift, but at the very least nullability annotations are a win here.</div><div class=""><br class=""></div><div class="">Thanks,</div><div class="">Robert Thompson</div><div class=""><div class="">Software Engineer</div><div class="">WillowTree, Inc.®</div><div class=""><a href="http://willowtreeapps.com/" target="_blank" class="">willowtreeapps.com</a></div></div><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Mar 14, 2016, at 11:50 AM, Daniel Eggert via swift-corelibs-dev <<a href="mailto:swift-corelibs-dev@swift.org" class="">swift-corelibs-dev@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class=""><br class=""><blockquote type="cite" class="">On 14 Mar 2016, at 15:36, Philippe Hausler <<a href="mailto:phausler@apple.com" class="">phausler@apple.com</a>> wrote:<br class=""><br class="">I dont think we had an intention set forth for how that was to be implemented; honestly it was a bit of a “we dont know how this should be done for linux yet” when the initial API drafts were posted. That being said NSURLSession and friends are definitely pretty important areas in Foundation (hence why the placeholder implementations are there).<br class=""><br class="">libcurl is readily available for linux (but we would need to alter our dependencies list for apt-get) and also is shipped for Darwin targets as well. so in spirit it might be a decent place to start.<br class=""><br class="">There are a few places that might need some research on how to approach an implementation:<br class=""><br class="">1) Can curl’s APIs interface with run loops?<br class=""></blockquote><br class="">It interfaces very nicely with libdispatch -- is that an option?<br class=""><br class=""><blockquote type="cite" class="">2) Can curl’s API provide a reasonable implementation to back other APIs? NSURLCache, NSURLRequest, NSURLResponse, even older APIs like NSURLConnection?<br class=""></blockquote><br class="">As for NSURLRequest and NSURLResponse: These will need some 'glue' but should work nicely with libcurl's interface.<br class=""><br class="">NSURLConnection is a bit of an oddball due it it's ties to NSRunLoop -- but it can certainly be made to work with libcurl.<br class=""><br class="">NSURLCache: libcurl does not do any caching, and as a result the interaction with NSURLCache should be relatively straight forward.<br class=""><br class="">libcurl's COOKIELIST should be able to interact with NSHTTPCookieStorage:<br class=""><a href="https://curl.haxx.se/libcurl/c/CURLOPT_COOKIELIST.html" class="">https://curl.haxx.se/libcurl/c/CURLOPT_COOKIELIST.html</a><br class=""><br class=""><blockquote type="cite" class="">3) How would the background downloading part of NSURLSession be handled? Would it just elide that feature?<br class=""></blockquote><br class="">I would elide that for now. To support this, we'd need an independent daemon to do the downloading. That's quite a project on its own.<br class=""><br class=""><blockquote type="cite" class="">4) Can it handle the delegation protocols for all events? If not, can the events be synthesized?<br class=""></blockquote><br class="">It appears that this should work nicely. libcurl provides callbacks as headers are parsed.<br class=""><br class="">One main pinpoint will be SSL / TLS support. That'll depend entirely on how libcurl is compiled and will not be able to pick up TLSMinimumSupportedProtocol / TLSMaximumSupportedProtocol. Also interaction with the NSURLAuthenticationChallenge and TLS remains a question. libcurl does provide a hook for this, but it's not trivial since the code will have to interact with the underlying TLS implementation.<br class=""><br class=""><br class="">Any implementation will depend on NSOperation / NSOperationQueue -- and those will in turn to some extend depend on libdispatch being available.<br class=""><br class="">And once libdispatch is available, it makes sense to use it for libcurl, too.<br class=""><br class="">/Daniel<br class=""><br class="">_______________________________________________<br class="">swift-corelibs-dev mailing list<br class=""><a href="mailto:swift-corelibs-dev@swift.org" class="">swift-corelibs-dev@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-corelibs-dev<br class=""></div></div></blockquote></div><br class=""></div></div>_______________________________________________<br class="">swift-corelibs-dev mailing list<br class=""><a href="mailto:swift-corelibs-dev@swift.org" class="">swift-corelibs-dev@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-corelibs-dev<br class=""></div></blockquote></div><br class=""></body></html>