Search code examples
httplibcurlcomet

Libcurl chunked http message received callback


Does libcurl expose some callback to be called when chunked http message is received? One server establishs comet-based http connection with a client. So client sends request to open connection using regular http, server responses with chunked http message which contains information to be processed by a client. Using opened connection several messages might be sent by server to a client on one http request. Each must be processed differently.

Is there a way to get this messages once their are sent without waiting for conection to be closed?


Solution

  • libcurl does not expose the chunk limits/borders by default, if that's what you're asking. libcurl will "decode" chunked encoded data and call the write callback with the payload contents, without revealing the chunks to the application. libcurl may then call the write callback one or more times for each incoming chunk.

    Optionally, you go the more hard-core route and ask libcurl to deliver the data "unencoded", so that your callback gets the entire thing, including the chunked-encoding meta-data so that you get to decode that yourself. You can tell libcurl to do that by using the CURLOPT_HTTP_CONTENT_DECODING option.