0

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?

dShapo
  • 1
  • Two things seem to be crucial: setting `"Connection":"keep-alive"`, which makes sense since chunked transfer is a persistent connection and manually setting `req->chunked = 1` before executing the request. This makes a bit less sense to me. I would expect setting the `"Transfer-Encoding":"chunked"` to be enough. – dShapo Mar 02 '23 at 08:51

0 Answers0