networking · intermediate · ~15 min

Find a header value

Look up an HTTP header value.

Challenge

Implement int header_value(const char *req, const char *name, char *out, int outsz) finding a header line Name: value and copying value (after ": ") into out, returning its length, or -1 if not found.

Starter code

#include <string.h>

int header_value(const char *req, const char *name, char *out, int outsz) {
    /* TODO */
    return -1;
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.