Skip to content

Pass request Task to FileDownloadDelegate reportHead and reportProgress closures #681

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 13, 2023

Conversation

dnadoba
Copy link
Collaborator

@dnadoba dnadoba commented Apr 12, 2023

Motivation

If the HTTP response status is not 2xx or the file being downloaded becomes too big, it is desirable to cancel the file download eagerly. This is currently quite hard because the reportHead and reportProgress closures do not have direct access to the HTTPClient.Task.

Modifications

  • Pass HTTPClient.Task additionally to reportHead and reportProgress closures

Result

A file download can now easily be cancelled at any time.

…tProgress` closures

### Motivation
If the HTTP response status is not 2xx or the file being downloaded becomes too big, it is desirable to cancel the file download eagerly. This is currently quite hard because the `reportHead` and `reportProgress` closures do not have direct access to the `HTTPClient.Task`.

### Modifications
- Pass `HTTPClient.Task` additionally to `reportHead` and `reportProgress` closures

### Result
A file download can now easily be cancelled at any time.
@dnadoba dnadoba added the 🆕 semver/minor Adds new public API. label Apr 12, 2023
@dnadoba dnadoba requested a review from MaxDesiatov April 12, 2023 18:27
Copy link
Member

@MaxDesiatov MaxDesiatov left a comment

Choose a reason for hiding this comment

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

This looks like a quite more elegant solution. Much appreciated!

@Lukasa Lukasa merged commit 45626d3 into swift-server:main Apr 13, 2023
@dnadoba dnadoba deleted the dn-forward-request-task branch April 13, 2023 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🆕 semver/minor Adds new public API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants