cgiSetHeader(3)

πŸ“¦ version 0.6, in ubuntu jammy

πŸ’– cgiSetHeader(3) β€” the Programmer's Manual glow-up πŸ’–

okay bestie, gather round, because today we're talking about cgiSetHeader from the CGI Library programmer's manual. she's a little function with main character energy and she's here to help you slap extra HTTP headers onto your output. no cap. πŸŽ€


✨ NAME ✨

cgiSetHeader β€” specify an additional HTTP header. that's it, that's the whole vibe. πŸ’…


🌸 SYNOPSYS 🌸

#include <cgi.h>

int cgiSetHeader (char *name, char *value);

like, that's the entire signature, she's lowkey simple and we love that for her. πŸ¦‹


πŸ’œ DESCRIPTION πŸ’œ

so with the cgiSetHeader routine you can specify additional HTTP header lines β€” think stuff like Expires: or Pragma:. and here's the tea: the order of header lines within the HTTP header has no significance whatsoever. it literally does not matter. πŸ’€

you can call this routine multiple times to set multiple headers, and they will be printed in the same order as you specified them β€” but they show up after the Content-type: header. so if you were expecting your headers to jump the queue, nope, Content-type: is first in line and she knows it. πŸ‘‘

ngl, one thing you gotta know: this routine will only add the header to the internal stack, it does not print it. nothing gets printed yet. they will be printed by cgiHeader(3) later. so don't panic if your terminal stays quiet β€” that's the whole point, it's giving "wait for it" energy. πŸ™ˆ

also she does some syntax checking before accepting a new header, because she has standards:

  • the name of a header must not contain any newline, space or colon β€” otherwise it will be truncated.
  • the value must not contain any newline β€” otherwise it will be truncated as well.
⚠️ so like, yes, truncation is real and she will do it. keep your names clean and your values newline-free, bestie. 🌈

to set a cookie in your program you'll need to manually add additional header lines. please take a look at cgitest.c. basically, you'll need to add the following code:

cgiSetHeader ("Set-Cookie", "Version=1; name=value; Path=/");
cgiHeader();

and please read the included file cookies.txt as well. 🫢


⭐ RETURN VALUE ⭐

on success, 1 is returned. otherwise, 0. that's the whole scale, she doesn't do grey areas. πŸ’…


🧚 AUTHOR 🧚

this CGI library is written by Martin Schulze <joey@infodrom.org>. if you have additions or improvements please get in touch with him. he's the icon, the legend, the moment. πŸ‘‘


🌈 SEE ALSO 🌈


and that's the whole page, bestie. this one's from the CGI Library, dated 6 April 2008, and she's still slaying fr fr. go forth and set those headers. πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from
  • ubuntu jammy: cgilib 0.6-1.1
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms