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

Add http_download function to simplify downloading files #433

Merged
merged 2 commits into from
May 6, 2024

Conversation

tigitz
Copy link
Contributor

@tigitz tigitz commented Apr 23, 2024

Continuation of #293

It narrows the scope to a simple http_download() function for now. Separates http_upload() into its own future PR due to its unique complexities and diverse HTTP upload methods.

Feature details are in the documentation.

@tigitz tigitz force-pushed the add-http-download branch 2 times, most recently from 2d329e3 to bd2261d Compare April 23, 2024 21:10
@TheoD02
Copy link
Contributor

TheoD02 commented Apr 23, 2024

Why not use on_progress directly ? https://symfony.com/doc/current/http_client.html#progress-callback
In that case the progress will be possible when $stream is true or false.

The only point that can be not good idea is if the user override the on_progress, it will will loose the default behavior purposed by castor

WDYT about add a progress bar as progress indicator for no verbose case ? This might be useful on large files or for those want to show progress anyway

Copy link
Member

@lyrixx lyrixx left a comment

Choose a reason for hiding this comment

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

I didn't review the download implementation yet, but it's a good start

CHANGELOG.md Outdated Show resolved Hide resolved
examples/http.php Outdated Show resolved Hide resolved
src/Http/HttpHelper.php Outdated Show resolved Hide resolved
src/Http/HttpHelper.php Outdated Show resolved Hide resolved
@tigitz
Copy link
Contributor Author

tigitz commented Apr 24, 2024

@TheoD02

Why not use on_progress directly ? https://symfony.com/doc/current/http_client.html#progress-callback
In that case the progress will be possible when $stream is true or false.

The only point that can be not good idea is if the user override the on_progress, it will will loose the default behavior purposed by castor

I initially dismissed this idea for the reason you highlighted. However, upon reflection, I could wrap the user's on_progress callback with our implementation.

WDYT about add a progress bar as progress indicator for no verbose case ? This might be useful on large files or for those want to show progress anyway

I considered this too but opted to avoid cluttering the standard output by default since, as far as I know, few native Castor functions currently output anything. I aimed to maintain consistency by making the progress display an "opt-in" mechanism, leveraging the existing verbose feature for this purpose.

I'm open to either approach. Let's hear what others have to suggest.

@lyrixx
Copy link
Member

lyrixx commented Apr 24, 2024

I considered this too but opted to avoid cluttering the standard output by default since, as far as I know, few native Castor functions currently output anything. I aimed to maintain consistency by making the progress display an "opt-in" mechanism, leveraging the existing verbose feature for this purpose.

yes, let's be silent by default 👍🏼

@tigitz
Copy link
Contributor Author

tigitz commented Apr 27, 2024

@lyrixx Updated according to your suggestions, I left the HttpRequester->httpClient() for now as it's not clear to me what's expected.

@TheoD02 I switched to the onprogress option as discussed. As expected, download progress code is now simpler and also work for non stream downloads. 🙂

Copy link
Member

@lyrixx lyrixx left a comment

Choose a reason for hiding this comment

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

except nitpicking, it looks good 👍🏼

doc/going-further/helpers/http-request.md Show resolved Hide resolved
doc/going-further/helpers/http-request.md Outdated Show resolved Hide resolved
examples/http.php Outdated Show resolved Hide resolved
src/Http/HttpRequester.php Outdated Show resolved Hide resolved
src/Http/HttpRequester.php Outdated Show resolved Hide resolved
src/Http/HttpRequester.php Outdated Show resolved Hide resolved
src/Http/HttpRequester.php Outdated Show resolved Hide resolved
@tigitz tigitz force-pushed the add-http-download branch 5 times, most recently from a8b6621 to 046b382 Compare May 4, 2024 16:49
@lyrixx
Copy link
Member

lyrixx commented May 6, 2024

Hi, for the record, I have finished this PR. I fixed all my comments, and I also rebased.

Copy link
Member

@pyrech pyrech left a comment

Choose a reason for hiding this comment

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

Just a small question in the doc, but looks go to me otherwise. Thanks to both of you :)

Comment on lines 28 to 29
The `stream` parameter controls whether the download is chunked (`true`), which
is useful for large files as it uses less memory, or in one go (`false`).
Copy link
Member

Choose a reason for hiding this comment

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

Should we mention the default value?

@lyrixx lyrixx merged commit 916092d into jolicode:main May 6, 2024
9 checks passed
@tigitz
Copy link
Contributor Author

tigitz commented May 6, 2024

@lyrixx Ah, now I understand! You wanted me to keep the HttpClientInterface alongside the newly introduced HttpDownloader instead of merging all HTTP responsibilities into a single HttpRequester class.

Thank you for completing the work! 👍 I hope it will be useful for others.

@lyrixx
Copy link
Member

lyrixx commented May 6, 2024

yes, Single Responsibility for the win 👍🏼

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.

None yet

4 participants