Skip to content
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

Support URLSessionDataTask to URLSessionDownloadTask Upgrades #3433

Open
1 task done
hiltonc opened this issue Apr 12, 2021 · 2 comments
Open
1 task done

Support URLSessionDataTask to URLSessionDownloadTask Upgrades #3433

hiltonc opened this issue Apr 12, 2021 · 2 comments

Comments

@hiltonc
Copy link

hiltonc commented Apr 12, 2021

ℹ Please fill out this template when filing a feature request.
All lines beginning with an ℹ symbol instruct you with what info we expect. You can delete those lines once you've filled in the info.

Feature requests should code examples whenever possible.

Per our *CONTRIBUTING guidelines, we use GitHub for
bugs and feature requests, not general support. Other issues should be opened on Stack Overflow with the tag alamofire.

Please remove this line and everything above it before submitting.

Problem

Currently when I download a file using AF.download, if the request fails the error response is downloaded. I'm only interested in the status code and don't want to download the error content, or at least I don't want to download the error content as the file.

Feature Request

Provide a way to either not download the error content, or download it in memory and not to a file.

Value to Alamofire

This seems like a reasonable way to handle download errors in general, but it seems like Alamofire doesn't provide a way to do it.

@jshier
Copy link
Contributor

jshier commented Apr 12, 2021

This could be a useful general feature, not just for downloads but for all request types. We can implement urlSession(_:dataTask:didReceive:completionHandler:) and call back to the request to allow for customization. However, URLSession only allows for cancellation here, which isn't the greatest experience in the response, so we would probably need to map it into a better value or error.

@jshier jshier changed the title Option to not download an error response with AF.download Allow customization of initial HTTPURLResponse handling Apr 12, 2021
@jshier
Copy link
Contributor

jshier commented Oct 21, 2021

Further investigation shows that properly supporting this sort of flow (check initial response for a successful code or other success state, download data if it's an error, but download a file to disk if it's a success) is only possible if Alamofire supports turning URLSessionDataTasks into URLSessionDownloadTasks, which isn't possible given the current architecture. This would be a very challenging design task, as Alamofire would not only need internal changes to support it, but would then need to design an API surface for a Request type that provides a mix of DataRequest and DownloadRequest functionality. A tall order but an interesting challenge.

Given that complexity and how easy it is create a custom ResponseSerializer that reads the failure Data from disk, it's unlikely Alamofire will ever support this functionality. I'll leave this issue open for now, pending further investigation.

@jshier jshier changed the title Allow customization of initial HTTPURLResponse handling Support URLSessionDataTask to URLSessionDownloadTask Evolution Oct 21, 2021
@jshier jshier changed the title Support URLSessionDataTask to URLSessionDownloadTask Evolution Support URLSessionDataTask to URLSessionDownloadTask Upgrades Oct 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants