libmicrohttpd

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

commit b452fc4b19e70f796147ca02349e5ec07afde738
parent 76ffb86c041863944e299d66e0e827de18287910
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date:   Sat, 19 Mar 2022 13:44:19 +0300

MHD_create_response_empty(): added new function

Diffstat:
Msrc/include/microhttpd.h | 21++++++++++++++++++++-
Msrc/microhttpd/response.c | 38++++++++++++++++++++++++++++++++++++++
2 files changed, 58 insertions(+), 1 deletion(-)

diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h @@ -96,7 +96,7 @@ extern "C" * they are parsed as decimal numbers. * Example: 0x01093001 = 1.9.30-1. */ -#define MHD_VERSION 0x00097502 +#define MHD_VERSION 0x00097503 /* If generic headers don't work on your platform, include headers which define 'va_list', 'size_t', 'ssize_t', 'intptr_t', @@ -3760,6 +3760,25 @@ MHD_create_response_from_iovec (const struct MHD_IoVec *iov, /** + * Create a response object with empty (zero size) body. + * + * The response object can be extended with header information and then be used + * any number of times. + * + * This function is a faster equivalent of #MHD_create_response_from_buffer call + * with zero size combined with call of #MHD_set_response_options. + * + * @param flags the flags for the new response object + * @return NULL on error (i.e. invalid arguments, out of memory), + * the pointer to the created response object otherwise + * @note Available since #MHD_VERSION 0x00097503 + * @ingroup response + */ +_MHD_EXTERN struct MHD_Response * +MHD_create_response_empty (enum MHD_ResponseFlags flags); + + +/** * Enumeration for actions MHD should perform on the underlying socket * of the upgrade. This API is not finalized, and in particular * the final set of actions is yet to be decided. This is just an diff --git a/src/microhttpd/response.c b/src/microhttpd/response.c @@ -1592,6 +1592,44 @@ MHD_create_response_from_iovec (const struct MHD_IoVec *iov, } +/** + * Create a response object with empty (zero size) body. + * + * The response object can be extended with header information and then be used + * any number of times. + * + * This function is a faster equivalent of #MHD_create_response_from_buffer call + * with zero size combined with call of #MHD_set_response_options. + * + * @param flags the flags for the new response object + * @return NULL on error (i.e. invalid arguments, out of memory), + * the pointer to the created response object otherwise + * @note Available since #MHD_VERSION 0x00097503 + * @ingroup response + */ +struct MHD_Response * +MHD_create_response_empty (enum MHD_ResponseFlags flags) +{ + struct MHD_Response *r; + r = (struct MHD_Response *) MHD_calloc_ (1, sizeof (struct MHD_Response)); + if (NULL != r) + { + if (! MHD_mutex_init_ (&r->mutex)) + { + r->fd = -1; + r->reference_count = 1; + /* If any flags combination will be not allowed, replace the next + * assignment with MHD_set_response_options() call. */ + r->flags = flags; + + return r; /* Successful result */ + } + free (r); + } + return NULL; /* Something failed */ +} + + #ifdef UPGRADE_SUPPORT /** * This connection-specific callback is provided by MHD to