libmicrohttpd

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

commit 11e2fba331a7009f37c7595ceb35999bf1f4d1c0
parent aa0ae46cbcbdd9eda1cbc88d70e3cab2deb2b068
Author: Christian Grothoff <christian@grothoff.org>
Date:   Sun, 14 Nov 2010 19:49:13 +0000

footer support

Diffstat:
MChangeLog | 3+++
Mdoc/microhttpd.texi | 20+++++++++++++++++++-
Msrc/daemon/EXPORT.sym | 1+
Msrc/daemon/response.c | 60+++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
Msrc/include/microhttpd.h | 22++++++++++++++++++----
5 files changed, 96 insertions(+), 10 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -1,3 +1,6 @@ +Sun Nov 14 20:45:45 CET 2010 + Adding API call to generate HTTP footers in response. -CG + Sat Oct 16 12:38:43 CEST 2010 Releasing libmicrohttpd 0.9.2. -CG diff --git a/doc/microhttpd.texi b/doc/microhttpd.texi @@ -1327,8 +1327,26 @@ memory allocation error). @end deftypefun +@deftypefun int 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}. + +Notice that the strings must not hold newlines, carriage returns or tab +chars. 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 +in MHD 0.9.3. + +Return @code{MHD_NO} on error (i.e. invalid header or content format or +memory allocation error). +@end deftypefun + + + @deftypefun int MHD_del_response_header (struct MHD_Response *response, const char *header, const char *content) -Delete a header line from the response. Return @code{MHD_NO} on error +Delete a header (or footer) line from the response. Return @code{MHD_NO} on error (arguments are invalid or no such header known). @end deftypefun diff --git a/src/daemon/EXPORT.sym b/src/daemon/EXPORT.sym @@ -13,6 +13,7 @@ MHD_create_response_from_data MHD_create_response_from_fd MHD_destroy_response MHD_add_response_header +MHD_add_response_footer MHD_del_response_header MHD_get_response_headers MHD_get_response_header diff --git a/src/daemon/response.c b/src/daemon/response.c @@ -27,14 +27,21 @@ #include "internal.h" #include "response.h" + /** - * Add a header line to the response. + * Add a header or footer line to the response. * + * @param response response to add a header to + * @param kind header or footer + * @param header the header to add + * @param content value to add * @return MHD_NO on error (i.e. invalid header or content format). */ -int -MHD_add_response_header (struct MHD_Response *response, - const char *header, const char *content) +static int +add_response_entry (struct MHD_Response *response, + enum MHD_ValueKind kind, + const char *header, + const char *content) { struct MHD_HTTP_Header *hdr; @@ -65,15 +72,57 @@ MHD_add_response_header (struct MHD_Response *response, free (hdr); return MHD_NO; } - hdr->kind = MHD_HEADER_KIND; + hdr->kind = kind; hdr->next = response->first_header; response->first_header = hdr; return MHD_YES; } + +/** + * Add a header line to the response. + * + * @param response response to add a header to + * @param header the header to add + * @param content value to add + * @return MHD_NO on error (i.e. invalid header or content format). + */ +int +MHD_add_response_header (struct MHD_Response *response, + const char *header, const char *content) +{ + return add_response_entry (response, + MHD_HEADER_KIND, + header, + content); +} + + +/** + * Add a footer line to the response. + * + * @param response response to remove a header from + * @param footer the footer to delete + * @param content value to delete + * @return MHD_NO on error (i.e. invalid footer or content format). + */ +int +MHD_add_response_footer (struct MHD_Response *response, + const char *footer, const char *content) +{ + return add_response_entry (response, + MHD_FOOTER_KIND, + header, + content); +} + + /** * Delete a header line from the response. * + * @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) */ int @@ -107,6 +156,7 @@ MHD_del_response_header (struct MHD_Response *response, return MHD_NO; } + /** * Get all of the headers added to a response. * diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h @@ -106,7 +106,7 @@ extern "C" /** * Current version of the library. */ -#define MHD_VERSION 0x00090200 +#define MHD_VERSION 0x00090201 /** * MHD-internal return code for "YES". @@ -1194,8 +1194,22 @@ int MHD_add_response_header (struct MHD_Response *response, const char *header, const char *content); + +/** + * Add a footer line to the response. + * + * @param response response to remove a header from + * @param footer the footer to delete + * @param content value to delete + * @return MHD_NO on error (i.e. invalid footer or content format). + */ +int +MHD_add_response_footer (struct MHD_Response *response, + const char *footer, const char *content); + + /** - * Delete a header line from the response. + * Delete a header (or footer) line from the response. * * @param response response to remove a header from * @param header the header to delete @@ -1207,7 +1221,7 @@ MHD_del_response_header (struct MHD_Response *response, const char *header, const char *content); /** - * Get all of the headers added to a response. + * Get all of the headers (and footers) added to a response. * * @param response response to query * @param iterator callback to call on each header; @@ -1221,7 +1235,7 @@ MHD_get_response_headers (struct MHD_Response *response, /** - * Get a particular header from the response. + * Get a particular header (or footer) from the response. * * @param response response to query * @param key which header to get