NE_GET_RESPONSE_HEAD(3)

πŸ“¦
version 0.37.1 Β· 3 versions
, in epel 10, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable

πŸ’– NE_GET_RESPONSE_HEAD(3) β€” the neon API reference glow-up πŸ’–

okay bestie, so this is a page from the neon API reference (that's the manual name, consider it folded in like a lil note in your lunchbox πŸŽ€). It's all about the functions that go digging around in your HTTP response headers and trailers. Four of them. They're a little family. Let's meet them ✨


✨ NAME ✨

ne_get_response_header, ne_get_response_trailer, ne_response_header_iterate, ne_response_trailer_iterate β€” functions to access response headers and trailers

like literally the whole point of them. no notes. πŸ‘‘


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <ne_request.h>

const char *ne_get_response_header(ne_request *request,
                                   const char *name);

const char *ne_get_response_trailer(ne_request *req, const char *name);

void *ne_response_header_iterate(ne_request *request, void *cursor,
                                 const char **name, const char **value);

void *ne_response_trailer_iterate(ne_request *request, void *cursor,
                                  const char **name,
                                  const char **value);

she's giving clean signatures πŸ’…


🌸 DESCRIPTION 🌸

So you wanna know what a response header field says? Say less. You use ne_get_response_header, and you hand her the name of the header you're craving and she gives you the goods.

And listen β€” if multiple HTTP response headers come back with the same name (rude of them tbh), their values get combined together into one comma-separated list. All of them. Together. Besties holding hands. 🫢


Now for the trailer era. If you want a header value from a chunked response trailer section β€” and yes, that's the part that gets sent after the response body instead of before it, iconic behaviour honestly β€” you use ne_get_response_trailer. Otherwise it's the exact same semantics as ne_get_response_header. Same vibes, different section.

⚠️ ok but fr: trailer fields are used rarely and you should interpret them with care. See RFC 9110 §6.5[1]. Not me warning you twice. 😭

Wanna iterate over all the response headers instead of just one? That's ne_response_header_iterate's whole moment. She takes a cursor parameter, and to get the first header you set that cursor to NULL. She stores the name and value of the next header into the name and value parameters, and she returns a new cursor pointer that you pass right back into ne_response_header_iterate to get the next header. Rinse, repeat, slay. ✨

And ne_response_trailer_iterate? Same semantics as ne_response_header_iterate, except she operates on the response trailer fields instead of the header section. Same energy, different section, you know the drill. πŸ’œ


πŸ’€ RETURN VALUE πŸ’€

ne_get_response_header and ne_get_response_trailer each return a string, or NULL if no header or trailer field with that name was found. Ghosted. Not found. That's the NULL.

🚨 Big important thing: the return value pointer is valid only until the next call to ne_begin_request or ne_request_destroy for the same request. Do not go keeping that pointer around like it's yours. It is not. It's temporary. It's giving situationship. 😭

Likewise, the cursor, names, and values returned by ne_response_header_iterate or ne_response_trailer_iterate are only valid until the next call to ne_begin_request or until the request object is destroyed. Same rule, same energy, no cap. πŸ’…


🌈 EXAMPLES 🌈

The following code will output the value of the Last-Modified header for a resource:

ne_request *req = ne_request_create(sess, "GET", "/foo.txt");
if (ne_request_dispatch(req) == NE_OK) {
    const char *mtime = ne_get_response_header(req, "Last-Modified");
    if (mtime) {
        printf("/foo.txt has last-modified value %s\n", mtime);
    }
}
ne_request_destroy(req);

look at her. so neat. so composed. she ate and left no crumbs πŸ“


⭐ HISTORY ⭐

ne_get_response_trailer and ne_response_trailer_iterate are available in neon 0.37.0 and later. In older releases, trailer fields were merged with normal response headers and could be accessed using ne_get_response_header or ne_response_header_iterate. So if you're on an ancient version, that's why your trailer functions aren't picking up the phone. πŸ™ˆ


πŸ‘‘ SEE ALSO πŸ‘‘

go read those too, they're the main characters of this whole saga 🫢


Copyright Β© 2001-2026 Joe Orton


πŸ”₯ REFERENCES πŸ”₯

  1. RFC 9110 Β§6.5 β€” https://www.rfc-editor.org/rfc/rfc9110.html#name-trailer-fields

okay that's the whole page, you're fully caught up bestie πŸ’– this was neon 0.37.1, dated 15 March 2026 β€” mwah, go forth and read your headers responsibly, periodt. πŸŒΈπŸ’…βœ¨

πŸ“¦ where this page comes from