Copyright ©

Mongoose OS Forum

ATTENTION! This forum has moved to:

Do not post any new messages.

Add header to response

edited September 2016 in Mongoose Networking Library

The old version of Mongoose had this function, which adds a line to the response header:

void mg_send_header(struct mg_connection *, const char *name,
const char *value);

What is the equivalent to this in the new version? The nearest I can find is this:

void mg_send_head(struct mg_connection *n, int status_code,
int64_t content_length, const char *extra_headers);

But this seems totally different. I don't want to set the status code, I don't know the content length, I just want to add a single response header.


  • I see that the approach is to use a custom mg_serve_http_opts structure.

  • SergeySergey Dublin, Ireland

    You can always use mg_printf() or mg_send() functions, which are the lowest-level API for appending data to the output buffer. Adding an HTTP header is as simple as

    mg_printf(conn, "%s: %s\r\n", "HEADER_NAME", "HEADER_VALUE");
  • Thanks Sergey, understood.

Sign In or Register to comment.