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

Modify ImageDownloaderDelegate to accept URLReponse #1676

Merged
merged 2 commits into from
Apr 10, 2021

Conversation

FaizanDurrani
Copy link
Contributor

Changed imageDownloader(_:didDownload:for:) to imageDownloader(_:didDownload:with:) accepting the returned URLResponse from the request.

This allows modifying the image data (like decrypting) based on the response the server sends (for example a specific header)

Changed `imageDownloader(_:didDownload:for:)` to `imageDownloader(_:didDownload:with:)` accepting the returned URLResponse from the request.

This allows modifying the image data (like decrypting) based on the response the server sends (for example a specific header)
@onevcat
Copy link
Owner

onevcat commented Apr 6, 2021

@FaizanDurrani

Thanks for this PR.

I believe it is a good direction and I'd like to have this in the new version. However, the implementation here breaks the public API and it requires a major upgrade. I am not sure if it worths a major version for just this commit. Can you try to keep the original protocol method (and mark it as deprecated), while adding a new delegate method? It would be nice that all the current behavior not changed.

Sure. If you do not have time for this, please feel free to let me know and I can also do it later when I can find more spare time.

Best regards.

Should maintain compatibility with existing implementations while notifying users to change the implementation to the newer `URLResponse` version
@FaizanDurrani
Copy link
Contributor Author

FaizanDurrani commented Apr 7, 2021

Updated the PR to not break the existing implementations. that being said, there is a slight catch to this, intead of passing the originalUrl, the url is taken from the URLResponse which is the final url after all the redirects, this may or may not be an issue.

A potential fix for it would be to also pass in the original URLRequest or the whole URLSessionDataTask instead of just the response so the method signature becomes:

imageDownloader(_: ImageDownloader, didDownload data: Data, for task: URLSessionDataTask) -> Data?

@onevcat
Copy link
Owner

onevcat commented Apr 8, 2021

Yes. It would be nicer and should be no harm to pass the whole task here. I will try to improve it, add documentation and tests after merging it.

Thanks!

@onevcat onevcat merged commit d24b6ee into onevcat:master Apr 10, 2021
onevcat added a commit that referenced this pull request Apr 21, 2021
Modify ImageDownloaderDelegate to accept URLReponse
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