I am running into an issue that I am having where the mongoose web server is delivering events to unexpected callback functions.
I have a endpoint registered with mg_register_http_endpoint that is in charge of sending random data to the client as a file. On MG_EV_HTTP_REQUEST (endpoint handler is invoked as expected), I generate a HTTP header and send to the client with a file size to be downloaded. The idea is that data is then sent to the client in 512 byte chunks until the desired file size is reached.
I was then planning on using the MG_EV_SEND event to know when the previous data had been sent so I can generate the next random 512 byte chunk to send to the client. However, the MG_EV_SEND event is delivered to the event handler that I provided in the mg_bind API call, and not the one provided in mg_http_register_endpoint(). Is this the correct behavior? If so, is there any disadvantage to overwriting the nc->handler function pointer to my endpoint function inside of the MG_EV_HTTP_REQUEST? That way all events on the connection will be delivered to my endpoint handler, rather than the one in mg_bind. From looking at the code, it seems like this is done for websockets.