libmicrohttpd

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

commit d3ae3c432d1d83bf5d300ca4670aa2626c574496
parent f71019f00b1d4b31b01dac2f98b46040cdd67b7e
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date:   Mon, 18 Apr 2022 11:17:45 +0300

Added new API function MHD_create_response_from_buffer_static()

Diffstat:
Msrc/include/microhttpd.h | 28+++++++++++++++++++++++++++-
Msrc/microhttpd/response.c | 32++++++++++++++++++++++++++++++++
2 files changed, 59 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 0x00097505 +#define MHD_VERSION 0x00097506 /* If generic headers don't work on your platform, include headers which define 'va_list', 'size_t', 'ssize_t', 'intptr_t', @@ -3539,6 +3539,32 @@ MHD_create_response_from_buffer (size_t size, /** + * Create a response object with the content of provided statically allocated + * buffer used as the response body. + * + * The buffer must be valid for the lifetime of the response. The easiest way + * to achieve this is to use a statically allocated buffer. + * + * The response object can be extended with header information and then + * be used any number of times. + * + * If response object is used to answer HEAD request then the body + * of the response is not used, while all headers (including automatic + * headers) are used. + * + * @param size the size of the data in @a buffer, can be zero + * @param buffer the buffer with the data for the response body, can be NULL + * if @a size is zero + * @return NULL on error (i.e. invalid arguments, out of memory) + * @note Available since #MHD_VERSION 0x00097506 + * @ingroup response + */ +_MHD_EXTERN struct MHD_Response * +MHD_create_response_from_buffer_static (size_t size, + const void *buffer); + + +/** * Create a response object with the content of provided buffer used as * the response body. * diff --git a/src/microhttpd/response.c b/src/microhttpd/response.c @@ -1379,6 +1379,38 @@ MHD_create_response_from_buffer (size_t size, /** + * Create a response object with the content of provided statically allocated + * buffer used as the response body. + * + * The buffer must be valid for the lifetime of the response. The easiest way + * to achieve this is to use a statically allocated buffer. + * + * The response object can be extended with header information and then + * be used any number of times. + * + * If response object is used to answer HEAD request then the body + * of the response is not used, while all headers (including automatic + * headers) are used. + * + * @param size the size of the data in @a buffer, can be zero + * @param buffer the buffer with the data for the response body, can be NULL + * if @a size is zero + * @return NULL on error (i.e. invalid arguments, out of memory) + * @note Available since #MHD_VERSION 0x00097506 + * @ingroup response + */ +_MHD_EXTERN struct MHD_Response * +MHD_create_response_from_buffer_static (size_t size, + const void *buffer) +{ + return MHD_create_response_from_buffer_with_free_callback_cls (size, + buffer, + NULL, + NULL); +} + + +/** * Create a response object with the content of provided buffer used as * the response body. *