libmicrohttpd

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

commit 32a9f1dc4df378defaf1d5e7252b9241921f2191
parent 91a0d62efd3669163481e5a09195746471ccfa59
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date:   Tue,  8 Jun 2021 13:56:38 +0300

response: added MHD_get_response_element_n() function

Diffstat:
Msrc/microhttpd/response.c | 36++++++++++++++++++++++++++++++++++++
Msrc/microhttpd/response.h | 19+++++++++++++++++++
2 files changed, 55 insertions(+), 0 deletions(-)

diff --git a/src/microhttpd/response.c b/src/microhttpd/response.c @@ -400,6 +400,42 @@ MHD_get_response_header (struct MHD_Response *response, /** + * Get a particular header (or footer) element from the response. + * + * Function returns the first found element. + * @param response response to query + * @param kind the kind of element: header or footer + * @param key the key which header to get + * @param key_len the length of the @a key + * @return NULL if header elemnt does not exist + * @ingroup response + */ +struct MHD_HTTP_Header * +MHD_get_response_element_n_ (struct MHD_Response *response, + enum MHD_ValueKind kind, + const char *key, + size_t key_len) +{ + struct MHD_HTTP_Header *pos; + + mhd_assert (NULL != key); + mhd_assert (0 != key[0]); + mhd_assert (0 != key_len); + + for (pos = response->first_header; + NULL != pos; + pos = pos->next) + { + if ((pos->header_size == key_len) && + (kind == pos->kind) && + (MHD_str_equal_caseless_bin_n_ (pos->header, key, pos->header_size))) + return pos; + } + return NULL; +} + + +/** * Check whether response header contains particular token. * * Token could be surrounded by spaces and tabs and delimited by comma. diff --git a/src/microhttpd/response.h b/src/microhttpd/response.h @@ -1,6 +1,7 @@ /* This file is part of libmicrohttpd Copyright (C) 2007 Daniel Pittman and Christian Grothoff + Copyright (C) 2015-2021 Karlson2k (Evgeny Grin) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -22,6 +23,7 @@ * @brief Methods for managing response objects * @author Daniel Pittman * @author Christian Grothoff + * @author Karlson2k (Evgeny Grin) */ #ifndef RESPONSE_H @@ -54,4 +56,21 @@ MHD_response_execute_upgrade_ (struct MHD_Response *response, struct MHD_Connection *connection); +/** + * Get a particular header (or footer) element from the response. + * + * Function returns the first found element. + * @param response response to query + * @param kind the kind of element: header or footer + * @param key the key which header to get + * @param key_len the length of the @a key + * @return NULL if header elemnt does not exist + * @ingroup response + */ +struct MHD_HTTP_Header * +MHD_get_response_element_n_ (struct MHD_Response *response, + enum MHD_ValueKind kind, + const char *key, + size_t key_len); + #endif