aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Grin (Karlson2k) <k2k@narod.ru>2021-06-08 13:56:38 +0300
committerEvgeny Grin (Karlson2k) <k2k@narod.ru>2021-06-20 16:25:21 +0300
commit32a9f1dc4df378defaf1d5e7252b9241921f2191 (patch)
treed77c197af22eb2231c41e47ec1e5ccf7e8690cc5
parent91a0d62efd3669163481e5a09195746471ccfa59 (diff)
downloadlibmicrohttpd-32a9f1dc4df378defaf1d5e7252b9241921f2191.tar.gz
libmicrohttpd-32a9f1dc4df378defaf1d5e7252b9241921f2191.zip
response: added MHD_get_response_element_n() function
-rw-r--r--src/microhttpd/response.c36
-rw-r--r--src/microhttpd/response.h19
2 files changed, 55 insertions, 0 deletions
diff --git a/src/microhttpd/response.c b/src/microhttpd/response.c
index 7e3deaf8..e1f2aebf 100644
--- a/src/microhttpd/response.c
+++ b/src/microhttpd/response.c
@@ -400,6 +400,42 @@ MHD_get_response_header (struct MHD_Response *response,
400 400
401 401
402/** 402/**
403 * Get a particular header (or footer) element from the response.
404 *
405 * Function returns the first found element.
406 * @param response response to query
407 * @param kind the kind of element: header or footer
408 * @param key the key which header to get
409 * @param key_len the length of the @a key
410 * @return NULL if header elemnt does not exist
411 * @ingroup response
412 */
413struct MHD_HTTP_Header *
414MHD_get_response_element_n_ (struct MHD_Response *response,
415 enum MHD_ValueKind kind,
416 const char *key,
417 size_t key_len)
418{
419 struct MHD_HTTP_Header *pos;
420
421 mhd_assert (NULL != key);
422 mhd_assert (0 != key[0]);
423 mhd_assert (0 != key_len);
424
425 for (pos = response->first_header;
426 NULL != pos;
427 pos = pos->next)
428 {
429 if ((pos->header_size == key_len) &&
430 (kind == pos->kind) &&
431 (MHD_str_equal_caseless_bin_n_ (pos->header, key, pos->header_size)))
432 return pos;
433 }
434 return NULL;
435}
436
437
438/**
403 * Check whether response header contains particular token. 439 * Check whether response header contains particular token.
404 * 440 *
405 * Token could be surrounded by spaces and tabs and delimited by comma. 441 * Token could be surrounded by spaces and tabs and delimited by comma.
diff --git a/src/microhttpd/response.h b/src/microhttpd/response.h
index 03448e56..52dece93 100644
--- a/src/microhttpd/response.h
+++ b/src/microhttpd/response.h
@@ -1,6 +1,7 @@
1/* 1/*
2 This file is part of libmicrohttpd 2 This file is part of libmicrohttpd
3 Copyright (C) 2007 Daniel Pittman and Christian Grothoff 3 Copyright (C) 2007 Daniel Pittman and Christian Grothoff
4 Copyright (C) 2015-2021 Karlson2k (Evgeny Grin)
4 5
5 This library is free software; you can redistribute it and/or 6 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public 7 modify it under the terms of the GNU Lesser General Public
@@ -22,6 +23,7 @@
22 * @brief Methods for managing response objects 23 * @brief Methods for managing response objects
23 * @author Daniel Pittman 24 * @author Daniel Pittman
24 * @author Christian Grothoff 25 * @author Christian Grothoff
26 * @author Karlson2k (Evgeny Grin)
25 */ 27 */
26 28
27#ifndef RESPONSE_H 29#ifndef RESPONSE_H
@@ -54,4 +56,21 @@ MHD_response_execute_upgrade_ (struct MHD_Response *response,
54 struct MHD_Connection *connection); 56 struct MHD_Connection *connection);
55 57
56 58
59/**
60 * Get a particular header (or footer) element from the response.
61 *
62 * Function returns the first found element.
63 * @param response response to query
64 * @param kind the kind of element: header or footer
65 * @param key the key which header to get
66 * @param key_len the length of the @a key
67 * @return NULL if header elemnt does not exist
68 * @ingroup response
69 */
70struct MHD_HTTP_Header *
71MHD_get_response_element_n_ (struct MHD_Response *response,
72 enum MHD_ValueKind kind,
73 const char *key,
74 size_t key_len);
75
57#endif 76#endif