From 07191755f3a38cbac48d15523095136f69d8f772 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Tue, 7 Oct 2025 18:48:44 -0700 Subject: http: implement nng_http_next_header --- src/supplemental/http/http_conn.c | 32 ++++++++++++++++++++++++++++++++ src/supplemental/http/http_public.c | 15 +++++++++++++++ 2 files changed, 47 insertions(+) (limited to 'src') diff --git a/src/supplemental/http/http_conn.c b/src/supplemental/http/http_conn.c index 93068512..6f2ecef6 100644 --- a/src/supplemental/http/http_conn.c +++ b/src/supplemental/http/http_conn.c @@ -1372,6 +1372,38 @@ http_get_header(const nni_list *hdrs, const char *key) return (NULL); } +static bool +http_next_header( + const nni_list *hdrs, const char **key, const char **val, void **ptr) +{ + http_header *h; + + if (*ptr == NULL) { + h = nni_list_first(hdrs); + } else { + h = nni_list_next(hdrs, *ptr); + } + if (h == NULL) { + return (false); + } + + *ptr = h; + *key = h->name; + *val = h->value; + return (true); +} + +bool +nni_http_next_header( + nng_http *conn, const char **key, const char **val, void **ptr) +{ + if (conn->client) { + return (http_next_header(&conn->res.data.hdrs, key, val, ptr)); + } else { + return (http_next_header(&conn->req.data.hdrs, key, val, ptr)); + } +} + const char * nni_http_get_header(nng_http *conn, const char *key) { diff --git a/src/supplemental/http/http_public.c b/src/supplemental/http/http_public.c index 5c7d8a77..419632fe 100644 --- a/src/supplemental/http/http_public.c +++ b/src/supplemental/http/http_public.c @@ -27,6 +27,21 @@ nng_http_get_header(nng_http *conn, const char *key) #endif } +nng_err +nng_http_next_header( + nng_http *conn, const char **key, const char **val, void **ptr) +{ +#ifdef NNG_SUP_HTTP + return (nni_http_next_header(conn, key, val, ptr)); +#else + NNI_ARG_UNUSED(conn); + NNI_ARG_UNUSED(key); + NNI_ARG_UNUSED(val); + NNI_ARG_UNUSED(ptr); + return (NNG_ENOTSUP); +#endif +} + nng_err nng_http_set_header(nng_http *conn, const char *key, const char *val) { -- cgit v1.2.3-70-g09d2