http
http copied to clipboard
Sharing CupertinoClient's URLSession
I have a use-case where I want to:
- Use URLSession directly to run efficient large-file downloadTask's.
- Make API calls using the simplified interface.
I would like to use the same URLSession for both of these. One way would be to allow a CupertinoClient to be constructed from a URLSession, another to make the internal URLSession public.
The problem is that CupertinoClient needs to control the URLSession delegate.
Why do you want to reuse the URLSession?
I am making many requests to a single service and would like to use the same connection pool and configuration. For many things I just use the general http interface, but I also need to use downloadTask which is not exposed outside URLSession.
The available options seem to be:
- Live with distinct URLSession's which seem suboptimal
- Only use URLSession directly, with the unfortunate effect of making everything platform specific
- Expand cupertino_http to have some convenience wrappers outside the currently standard http interface
- Allow sharing/using the URLSession one way or another
The problem is that CupertinoClient needs to control the URLSession delegate.
Ah, hmm. I suppose the newer async methods taking a URLSessionTaskDelegate would work better here. "Rewrite everything in Swift to use new async APIs" is a larger request than I intended to make though, so I will probably hack around it locally for now.