I'm trying to send (stream) data of an unknown size at the time of the POST request creation using the libevent's HTTP library. I'm creating the HTTP POST request as for the "classic" POST Request, except the "Transfer-Encoding" header parameter.
Here is the code snippet:
output_headers = evhttp_request_get_output_headers(req);
evhttp_add_header (output_headers, "Host", host);
evhttp_add_header (output_headers, "Connection", "close");
evhttp_add_header (output_headers, "Transfer-Encoding", "chunked");
evhttp_add_header (output_headers, "Content-Type", "application/gzip");
evhttp_make_request(evcon, req, EVHTTP_REQ_POST, path);
It seems like the test server accepts it (connection is not closed as it is without "Transfer-Encoding":"chunked"), but I have no idea how to use libevent API to send the chunks and eventually end the request.
I've seen some samples for the server side and I've tried to trick the evhttp_send_reply_chunk()
to the the job, but without success. As soon as first evhttp_send_reply_chunk() is executed I get EVREQ_HTTP_EOF and connection is closed.
I'm out of ideas how the send those chunks.
Does anyone have an idea how (if) this can be done?