NE_GET_RESPONSE_HEAD(3)

✨ NE_GET_RESPONSE_HEAD(3) ✨

okay so bestie, this is a page from the neon API reference and it's literally all about peeking at what the server sent back to you β€” the response headers and those sneaky little trailer fields. four functions, one glow-up. let's go πŸ’…


🌸 NAME 🌸

ne_get_response_header, ne_get_response_trailer, ne_response_header_iterate, ne_response_trailer_iterate β€” the functions that let you get at response headers and trailers πŸŽ€


πŸ¦‹ 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);

πŸ’– DESCRIPTION πŸ’–

So you wanna know the value of a response header field? iconic. use ne_get_response_header and just hand it the name of the header you want back. and like β€” important detail β€” if the server sends you multiple HTTP response headers with the same name, their values get smushed together into one comma-separated list. so you're not losing anything, it's giving "all my girls in one group chat" energy 🫢

now for the plot twist: trailer fields. those are headers that arrive after the response body, not before β€” chunked responses only, iykyk. to grab one of those bad boys you use ne_get_response_trailer. otherwise it's literally the same semantics as ne_get_response_header. but fr fr, trailer fields are used rarely and you should interpret them with care β€” check RFC 9110 Β§6.5 for the whole story (link's down in REFERENCES, don't worry πŸ’œ).

want to see every header instead of just one? that's ne_response_header_iterate. it takes a cursor parameter which should be <italic>NULL</italic> to get the first header. it stores the name and value of the next header in the name and value parameters, and returns you a fresh new cursor pointer β€” pass that back into ne_response_header_iterate to get the next one. rinse, repeat, slay ✨

and ne_response_trailer_iterate? same exact semantics as ne_response_header_iterate, except it operates on the response trailer fields instead of the header section. one twin is a header girlie, the other is a trailer girlie. πŸ’«


πŸŽ€ 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 (rip, nothing there πŸ™ˆ).

⚠️ the returned pointer is only valid until the next call to ne_begin_request or ne_request_destroy for the same request. do NOT be out here holding onto it forever, it will not survive. 😭

likewise, the cursor, names, and values you get back from 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 energy, same expiry date. πŸ’€


🌈 EXAMPLES 🌈

this little snippet will output the value of the Last-Modified header for a resource. main character code honestly:

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);

⭐ 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 just merged in with the normal response headers, so you could reach them with ne_get_response_header or ne_response_header_iterate. glow-up for the trailer girlies 🧚


πŸ‘‘ SEE ALSO πŸ‘‘

ne_request_create(3), ne_request_destroy(3).


Copyright Β© 2001-2026 Joe Orton


πŸ“ REFERENCES πŸ“

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

and that's the whole page bestie! this was neon, dated 03/20/2026, and the page you're on is NE_GET_RESPONSE_HEAD(3). go read your headers, stay hydrated, and remember: the pointer expires. always. πŸ’…πŸ¦‹βœ¨

πŸ“¦ where this page comes from