I think I have found a bug MHD_connection_handle_idle. If the application returns MHD_NO when connection is in MHD_CONNECTION_HEADERS_PROCESSED, connection state always changes to either MHD_CONNECTION_FOOTERS_RECEIVED or MHD_CONNECTION_CONTINUE_SENT while proper state would be MHD_CONNECTION_CLOSED.