Skip to content

Conversation

@crazytonyli
Copy link
Contributor

The consumer can now pass a URLSessionTaskDelegate instance to get notified of URLSession tasks that the Rust library sends.

At the moment, only a subset of URLSessionTaskDelegate and URLSessionDataDelegate functions will be called on the new parameter.

In the implementation, I had to stop using the async functions like await data(for: request, delegate: ...), and manually implement an async function using the dataTask(...) API. That's because the URLSession does not call the delegate's task result functions (didReceiveData, didReceiveResponse, didCompleteWithError), when the caller uses an API that returns the HTTP response. To make sure all the functions in the new notifyingDelegate: URLSessionTaskDelegate parameter get called, we had to manually workaround the URLSession constraints. Additionally, the async data(for: request, delegate: ...) API is not available API. If we want to support the new feature across all platforms, we have to implement the async API ourselves.

@crazytonyli crazytonyli requested a review from jkmassel November 26, 2025 09:26
platforms: [
.iOS(.v16),
.macOS(.v12),
.macOS(.v13),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some URLSessionTaskDelegate API is available on macOS 13. Bump this minimal macOS version to reduce a couple of if #available checks.

totalBytesSent: totalBytesSent,
totalBytesExpectedToSend: totalBytesExpectedToSend
)
#endif
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll see many similar code below, where we have two branches that call functions on Linux and Apple platforms. The difference is the .urlSession?(...) part. URLSessionTaskDelegate API is different on Linux and Apple platforms, because having optional functions in protocols is only available on Objective-C.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants