Pitch: Move URLSession to new FoundationNetworking module

Thanks Tony for the proposal and all the input received by others.

As Tony points out, SwiftNIO and other server related projects struggle a lot with the fact that Foundation does quite a few dependencies through libcurl which depends on a libssl (usually OpenSSL).

Another issue with using the platform's libcurl is that URLSession in swift-corelibs-foundation does support HTTP/2 if and only if the distribution's libcurl was compiled with HTTP/2 support (which it AFAIK isn't on Ubuntu 14.04 and 16.04).

So from our point of view there's a number of concrete problems with the current approach:

  • impossible to link another (newer) libcurl/libssl because of 'symbol clash' on Linux
  • too many dependencies on the system in Foundation (so static binaries with anything that uses Foundation are not possible right now with the standard Swift distributions)
  • development velocity of URLSession rather slow because of the coupling with the Swift distribution
  • unclear path to supporting HTTP/2 on all platforms (as the system's libcurl is linked which might or might not be compiled with HTTP/2 support)

Having URLSession in its own module that is distributed through SwiftPM would address most of those issues so I think it is a clear win. Yes, there's a similar issue with the dependency on libxml2 for XMLParser but let's deal with one issue at the time.

Obviously there are drawbacks too: Others have pointed out already that separating URLSession from Foundation comes source compatibility issues but also Data's init(contentsOf url: URL, ...) might be a problem...

@Tony_Parker is there any way we could move Darwin towards (soft) requiring a separate import for URLSession too? Of course we need to stay compatible but maybe we could have a warning issued if URLSession is used without also importing the new URLSession module?

2 Likes