yhirose/cpp-httplib

ContentReceiver chunk size cannot greater than 4096

Huweicai opened this issue · 0 comments

I am using cpp-httplib to watch server side events, instead of downloading some big files.

The interface looks like below while using curl
pic

My code looks like below:

auto res = cli.Get("/events,watch=true", [&](const char *data, size_t data_length) -> bool {
        auto event = json_parse(data, data_length);
        handle_event(event);
        return true;
    });

Each chunk stands for an event, but sometimes the event may be bigger than 4096, then it will be cut down, and json parse will fail.

I've seen the issue #1191, avoid to regard the data as a whole piece, but it's hard for me to distinguish the boundary of each event to put it together.

Do you have any good idea on it?

  • add another flag to indicate the chunk finished
  • increase the read buffer size