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 progress callback for http clients #23

Merged
merged 1 commit into from
Nov 25, 2017
Merged

add progress callback for http clients #23

merged 1 commit into from
Nov 25, 2017

Conversation

ruby0x1
Copy link
Contributor

@ruby0x1 ruby0x1 commented Nov 22, 2017

This is useful for displaying progress bars :) Here is how I use it.

progress

I tried to make the code idiomatic and avoided breaking any existing call sites.

httplib::Client client(url, port);

// prints: 0 / 000 bytes => 50% complete
std::shared_ptr<httplib::Response> res = 
    cli.get("/", [](int64_t len, int64_t total) {
        printf("%lld / %lld bytes => %d%% complete\n", 
            len, total,
            (int)((len/total)*100));
    }
);

@yhirose yhirose merged commit ad5fba4 into yhirose:master Nov 25, 2017
@yhirose
Copy link
Owner

yhirose commented Nov 25, 2017

@underscorediscovery, thanks for the contribution. This is truly a fantastic feature!

@ruby0x1 ruby0x1 deleted the progress-callback branch November 25, 2017 01:39
@ruby0x1
Copy link
Contributor Author

ruby0x1 commented Nov 25, 2017

no problem @yhirose , I have some more contributions but I am still working on them.
For the server, I have made a listen with non-blocking flag, and a poll function. It is also minimal changes but makes it easy to use without a thread. I am still testing on more platforms before PR, and I have some other things (like websocket) I can contribute also. Thanks for the lib btw, it's a nice simple basis to use :)

@hasanenalbana
Copy link

hasanenalbana commented Aug 4, 2018

Hi,
What is the best way to get result body from within this lambda function?

[Update]
I thought the function works in asynchronous mode, now it works just fine:

ExclusiveOrange pushed a commit to ExclusiveOrange/cpp-httplib-exor that referenced this pull request May 2, 2023
@315567599 315567599 mentioned this pull request Jul 8, 2024
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.

3 participants