http icon indicating copy to clipboard operation
http copied to clipboard

Sharing CupertinoClient's URLSession

Open kennylevinsen opened this issue 2 years ago • 3 comments

I have a use-case where I want to:

  1. Use URLSession directly to run efficient large-file downloadTask's.
  2. 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.

kennylevinsen avatar Aug 06 '23 16:08 kennylevinsen

The problem is that CupertinoClient needs to control the URLSession delegate.

Why do you want to reuse the URLSession?

brianquinlan avatar Aug 10 '23 19:08 brianquinlan

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:

  1. Live with distinct URLSession's which seem suboptimal
  2. Only use URLSession directly, with the unfortunate effect of making everything platform specific
  3. Expand cupertino_http to have some convenience wrappers outside the currently standard http interface
  4. 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.

kennylevinsen avatar Aug 11 '23 08:08 kennylevinsen