libmicrohttpd

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

commit 37593020c7a414e7e65bd56ad55a4ba8c1c832eb
parent 4d7d35d8a29b70659688db209b19db949994bc59
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date:   Sat, 21 Aug 2021 19:44:48 +0300

Added new connection state MHD_CONNECTION_REQ_LINE_RECEIVING

This allow to distinguish between connections received any data and
connections without any incoming data.

Diffstat:
Msrc/microhttpd/connection.c | 9+++++++++
Msrc/microhttpd/internal.h | 8+++++++-
2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c @@ -2238,6 +2238,7 @@ MHD_connection_update_event_loop_info (struct MHD_Connection *connection) switch (connection->state) { case MHD_CONNECTION_INIT: + case MHD_CONNECTION_REQ_LINE_RECEIVING: case MHD_CONNECTION_URL_RECEIVED: case MHD_CONNECTION_HEADER_PART_RECEIVED: /* while reading headers, we always grow the @@ -3529,6 +3530,7 @@ MHD_connection_handle_read (struct MHD_Connection *connection) switch (connection->state) { case MHD_CONNECTION_INIT: + case MHD_CONNECTION_REQ_LINE_RECEIVING: case MHD_CONNECTION_URL_RECEIVED: case MHD_CONNECTION_HEADER_PART_RECEIVED: case MHD_CONNECTION_HEADERS_RECEIVED: @@ -3597,6 +3599,7 @@ MHD_connection_handle_write (struct MHD_Connection *connection) switch (connection->state) { case MHD_CONNECTION_INIT: + case MHD_CONNECTION_REQ_LINE_RECEIVING: case MHD_CONNECTION_URL_RECEIVED: case MHD_CONNECTION_HEADER_PART_RECEIVED: case MHD_CONNECTION_HEADERS_RECEIVED: @@ -4103,6 +4106,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) switch (connection->state) { case MHD_CONNECTION_INIT: + case MHD_CONNECTION_REQ_LINE_RECEIVING: line = get_next_header_line (connection, &line_len); if (NULL != line) @@ -4110,8 +4114,11 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) /* Check for empty string, as we might want to tolerate 'spurious' empty lines */ if (0 == line[0]) + { /* TODO: Add MHD option to not tolerate it */ + connection->state = MHD_CONNECTION_INIT; continue; /* Process the next line */ + } if (MHD_NO == parse_initial_message_line (connection, line, line_len)) @@ -4130,6 +4137,8 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) mhd_assert (MHD_CONNECTION_INIT != connection->state); continue; } + if (0 < connection->read_buffer_offset) + connection->state = MHD_CONNECTION_REQ_LINE_RECEIVING; break; case MHD_CONNECTION_URL_RECEIVED: line = get_next_header_line (connection, diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h @@ -569,9 +569,15 @@ enum MHD_CONNECTION_STATE MHD_CONNECTION_INIT = 0, /** + * Part of the request line was received. + * Wait for complete line. + */ + MHD_CONNECTION_REQ_LINE_RECEIVING = MHD_CONNECTION_INIT + 1, + + /** * We got the URL (and request type and version). Wait for a header line. */ - MHD_CONNECTION_URL_RECEIVED = MHD_CONNECTION_INIT + 1, + MHD_CONNECTION_URL_RECEIVED = MHD_CONNECTION_REQ_LINE_RECEIVING + 1, /** * We got part of a multi-line request header. Wait for the rest.