Sending HTTP response in pieces


I need to send large (300k) HTTP responses from my Mongoose OS/ESP32 based application. I don’t have 300k contiguous free heap available.

It appears that all the mg_send_* calls buffer into memory (when servicing the HTTP request, I get the E:M log messages indicating that along the line an attempt is being made to allocate > 83000 bytes).

Is there a way to get Mongoose to send the response in smaller pieces?


Yes, check the send_iobuf length before mg_send_, and if it is larger than some reasonable threshold, do not send but rather wait for another poll cycle. This is what default file handler does.

Function mg_http_transfer_file_data()


ok, that makes perfect sense.

I see mg_http_transfer_file_data getting called at the beginning of the transfer (line 1549 on the current commit), and when EV_CLOSE is received (routine mg_http_handler, line 779). The latter surprises me; I would expect that call to mg_http_transfer_file_data to happen when EV_POLL or EV_SEND are received?

also, the http handler I registered with mgos_register_http_endpoint does not seem to get EV_POLL or EV_SEND events (or any events except the HTTP events). How do I detect the lower level events?


does anyone have any insight to lend here, especially around how to see EV_POLL and EV_SEND events?