libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit 85afdbaf90d645532b0eeb07d33c7c6f1b5b960f
parent ccd75de5b8513c5d78d5304ccc318b32b25a1844
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date:   Wed, 29 Sep 2021 17:49:02 +0300

transmit_error_response(): check whether it is still possible to send a response

Diffstat:
Msrc/microhttpd/connection.c | 27++++++++++++++++++++-------
1 file changed, 20 insertions(+), 7 deletions(-)

diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c @@ -2209,6 +2209,26 @@ transmit_error_response_len (struct MHD_Connection *connection, return; } connection->stop_with_error = true; +#ifdef HAVE_MESSAGES + MHD_DLOG (connection->daemon, + _ ("Error processing request (HTTP response code is %u ('%s')). " \ + "Closing connection.\n"), + status_code, + message); +#endif + if (MHD_CONNECTION_START_REPLY < connection->state) + { +#ifdef HAVE_MESSAGES + MHD_DLOG (connection->daemon, + _ ("Too late to send an error response, " \ + "response is being sent already.\n"), + status_code, + message); +#endif + CONNECTION_CLOSE_ERROR (connection, + _ ("Too late for error response.")); + return; + } /* TODO: remove when special error queue function is implemented */ connection->state = MHD_CONNECTION_FULL_REQ_RECEIVED; if (0 != connection->read_buffer_size) @@ -2221,13 +2241,6 @@ transmit_error_response_len (struct MHD_Connection *connection, 0); connection->read_buffer_size = 0; } -#ifdef HAVE_MESSAGES - MHD_DLOG (connection->daemon, - _ ( - "Error processing request (HTTP response code is %u (`%s')). Closing connection.\n"), - status_code, - message); -#endif if (NULL != connection->response) { MHD_destroy_response (connection->response);