networking · intermediate · ~15 min
Emit a status line, Content-Length, and body.
Implement int build_response(char *out, int outsz, int code, const char *body) writing HTTP/1.1 <code> OK\r\nContent-Length: <len>\r\n\r\n<body>. Return the length.
#include <stdio.h>
#include <string.h>
int build_response(char *out, int outsz, int code, const char *body) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.