libmicrohttpd

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

commit 449717db69384cafd740c7324fdf87aeadac22f7
parent cad66b87b8dfce1cca5f0562e7653a9b8967cfce
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date:   Tue, 19 Sep 2023 15:13:51 +0300

Added calculation of request headers total size

Diffstat:
Msrc/microhttpd/connection.c | 22++++++++++++++++++++--
Msrc/microhttpd/internal.h | 30++++++++++++++++++++++++++++++
2 files changed, 50 insertions(+), 2 deletions(-)

diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c @@ -4163,6 +4163,19 @@ reset_rq_header_processing_state (struct MHD_Connection *c) } +/** + * Switch to request headers (field lines) processing state. + * @param c the connection to process + */ +_MHD_static_inline void +switch_to_rq_headers_processing (struct MHD_Connection *c) +{ + c->rq.field_lines.start = c->read_buffer; + memset (&c->rq.hdrs.hdr, 0, sizeof(c->rq.hdrs.hdr)); + c->state = MHD_CONNECTION_REQ_HEADERS_RECEIVING; +} + + #ifndef MHD_MAX_EMPTY_LINES_SKIP /** * The maximum number of ignored empty line before the request line @@ -5614,6 +5627,11 @@ get_req_headers (struct MHD_Connection *c, bool process_footers) if (! process_footers) { c->rq.header_size = (size_t) (c->read_buffer - c->rq.method); + mhd_assert (NULL != c->rq.field_lines.start); + c->rq.field_lines.size = + (size_t) ((c->read_buffer - c->rq.field_lines.start) - 1); + if ('\r' == *(c->read_buffer - 2)) + c->rq.field_lines.size--; c->state = MHD_CONNECTION_HEADERS_RECEIVED; if (MHD_BUF_INC_SIZE > c->read_buffer_size) @@ -6513,8 +6531,8 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) mhd_assert (MHD_CONNECTION_REQ_LINE_RECEIVING >= connection->state); break; case MHD_CONNECTION_REQ_LINE_RECEIVED: - reset_rq_header_processing_state (connection); - connection->state = MHD_CONNECTION_REQ_HEADERS_RECEIVING; + switch_to_rq_headers_processing (connection); + mhd_assert (MHD_CONNECTION_REQ_LINE_RECEIVED != connection->state); continue; case MHD_CONNECTION_REQ_HEADERS_RECEIVING: if (get_req_headers (connection, false)) diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h @@ -1041,6 +1041,26 @@ union MHD_HeadersProcessing struct MHD_HeaderProcessing hdr; }; + +/** + * The union of text staring point and the size of the text + */ +union MHD_StartOrSize +{ + /** + * The starting point of the text. + * Valid when the text is being processed and the end of the text + * is not yet determined. + */ + const char *start; + /** + * The size of the text. + * Valid when the text has been processed and the end of the text + * is known. + */ + size_t size; +}; + /** * Request-specific values. * @@ -1104,6 +1124,16 @@ struct MHD_Request size_t header_size; /** + * The union of the size of all request field lines (headers) and + * the starting point of the first request field line (the first header). + * Until #MHD_CONNECTION_HEADERS_RECEIVED the @a start member is valid, + * staring with #MHD_CONNECTION_HEADERS_RECEIVED the @a size member is valid. + * The size includes CRLF (or LR) characters, but does not include + * the terminating empty line. + */ + union MHD_StartOrSize field_lines; + + /** * How many more bytes of the body do we expect * to read? #MHD_SIZE_UNKNOWN for unknown. */