libmicrohttpd

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

commit 3bb2c3c767dedd81505baf6465667880a4ebaedd
parent 79b1d76e6775e5e42485a0cb794cb115e25fa338
Author: Evgeny Grin (Karlson2k) <k2k@drgrin.dev>
Date:   Fri, 27 Nov 2026 12:45:10 +0100

Clarified handling of response header strings

Diffstat:
Mdoc/libmicrohttpd.texi | 27+++++++++++++++------------
Msrc/include/microhttpd.h | 30++++++++++++++++--------------
Msrc/microhttpd/response.c | 30++++++++++++++++--------------
3 files changed, 47 insertions(+), 40 deletions(-)

diff --git a/doc/libmicrohttpd.texi b/doc/libmicrohttpd.texi @@ -2208,12 +2208,10 @@ Return @code{NULL} on error (i.e. invalid arguments, out of memory). @deftypefun enum MHD_Result MHD_add_response_header (struct MHD_Response *response, const char *header, const char *content) -Add a header line to the response. The strings referenced by -@var{header} and @var{content} must be zero-terminated and they are -duplicated into memory blocks embedded in @var{response}. +Add a header line to the response. The strings @var{header} and +@var{content} are copied to the response. -Notice that the strings must not hold newlines, carriage returns or tab -chars. +The field name and value must be non-empty and conform to HTTP field syntax. MHD_add_response_header() prevents applications from setting a ``Transfer-Encoding'' header to values other than ``identity'' or @@ -2232,12 +2230,12 @@ memory allocation error). @deftypefun enum MHD_Result MHD_add_response_footer (struct MHD_Response *response, const char *footer, const char *content) -Add a footer line to the response. The strings referenced by -@var{footer} and @var{content} must be zero-terminated and they are -duplicated into memory blocks embedded in @var{response}. +Add a footer line to the response. The strings @var{footer} and +@var{content} are copied to the response. -Notice that the strings must not hold newlines, carriage returns or tab -chars. You can add response footers at any time before signalling the +The field name and value must be non-empty and conform to HTTP field syntax. + +You can add response footers at any time before signalling the end of the response to MHD (not just before calling 'MHD_queue_response'). Footers are useful for adding cryptographic checksums to the reply or to signal errors encountered during data generation. This call was introduced @@ -2250,8 +2248,13 @@ memory allocation error). @deftypefun enum MHD_Result MHD_del_response_header (struct MHD_Response *response, const char *header, const char *content) -Delete a header (or footer) line from the response. Return @code{MHD_NO} on error -(arguments are invalid or no such header known). +Delete a header (or footer) line from the response. For a ``Connection'' +header, @var{content} lists the tokens to remove. The header is deleted +if no tokens remain. + +Return @code{MHD_YES} if the header (or footer) or at least one +``Connection'' token has been removed, @code{MHD_NO} if no such header +(or footer) or token is found. @end deftypefun diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h @@ -4571,6 +4571,8 @@ MHD_destroy_response (struct MHD_Response *response); /** * Add a header line to the response. * + * The strings @a header and @a content are copied to the response. + * * When reply is generated with queued response, some headers are generated * automatically. Automatically generated headers are only sent to the client, * but not added back to the response object. @@ -4608,10 +4610,8 @@ MHD_destroy_response (struct MHD_Response *response); * Headers are used in order as they were added. * * @param response the response to add a header to - * @param header the header name to add, no need to be static, an internal copy - * will be created automatically - * @param content the header value to add, no need to be static, an internal - * copy will be created automatically + * @param header the header name to add + * @param content the header value to add * @return #MHD_YES on success, * #MHD_NO on error (i.e. invalid header or content format), * or out of memory @@ -4626,9 +4626,11 @@ MHD_add_response_header (struct MHD_Response *response, /** * Add a footer line to the response. * + * The strings @a footer and @a content are copied to the response. + * * @param response the response to add the footer to - * @param footer the name of the footer field to add - * @param content the value of the footer field to add + * @param footer the footer name to add + * @param content the footer value to add * @return #MHD_NO on error (i.e. invalid footer or content format). * @ingroup response */ @@ -4641,15 +4643,15 @@ MHD_add_response_footer (struct MHD_Response *response, /** * Delete a header (or footer) line from the response. * - * For "Connection" headers this function remove all tokens from existing - * value. Successful result means that at least one token has been removed. - * If all tokens are removed from "Connection" header, the empty "Connection" - * header removed. + * For a "Connection" header, @a content lists the tokens to remove. + * The header is deleted if no tokens remain. * - * @param response response to remove a header from - * @param header the header to delete - * @param content value to delete - * @return #MHD_NO on error (no such header known) + * @param response the response to remove a header from + * @param header the name of the header (or footer) to delete + * @param content the value of the header (or footer) to delete + * @return #MHD_YES if the header (or footer) or at least one "Connection" + * token has been removed, + * #MHD_NO if no such header (or footer) or token is found * @ingroup response */ _MHD_EXTERN enum MHD_Result diff --git a/src/microhttpd/response.c b/src/microhttpd/response.c @@ -575,6 +575,8 @@ del_response_header_connection (struct MHD_Response *response, /** * Add a header line to the response. * + * The strings @a header and @a content are copied to the response. + * * When reply is generated with queued response, some headers are generated * automatically. Automatically generated headers are only sent to the client, * but not added back to the response object. @@ -612,10 +614,8 @@ del_response_header_connection (struct MHD_Response *response, * Headers are used in order as they were added. * * @param response the response to add a header to - * @param header the header name to add, no need to be static, an internal copy - * will be created automatically - * @param content the header value to add, no need to be static, an internal - * copy will be created automatically + * @param header the header name to add + * @param content the header value to add * @return #MHD_YES on success, * #MHD_NO on error (i.e. invalid header or content format), * or out of memory @@ -716,9 +716,11 @@ MHD_add_response_header (struct MHD_Response *response, /** * Add a footer line to the response. * + * The strings @a footer and @a content are copied to the response. + * * @param response the response to add the footer to - * @param footer the name of the footer field to add - * @param content the value of the footer field to add + * @param footer the footer name to add + * @param content the footer value to add * @return #MHD_NO on error (i.e. invalid footer or content format). * @ingroup response */ @@ -737,15 +739,15 @@ MHD_add_response_footer (struct MHD_Response *response, /** * Delete a header (or footer) line from the response. * - * For "Connection" headers this function remove all tokens from existing - * value. Successful result means that at least one token has been removed. - * If all tokens are removed from "Connection" header, the empty "Connection" - * header removed. + * For a "Connection" header, @a content lists the tokens to remove. + * The header is deleted if no tokens remain. * - * @param response response to remove a header from - * @param header the header to delete - * @param content value to delete - * @return #MHD_NO on error (no such header known) + * @param response the response to remove a header from + * @param header the name of the header (or footer) to delete + * @param content the value of the header (or footer) to delete + * @return #MHD_YES if the header (or footer) or at least one "Connection" + * token has been removed, + * #MHD_NO if no such header (or footer) or token is found * @ingroup response */ _MHD_EXTERN enum MHD_Result