cybersecurity · intermediate · ~15 min · safe pentest lab
Read structured headers out of HTTP response text.
Pull a named header value out of an HTTP response — reading structured headers from raw response text.
Implement int find_header(const char *response, const char *name, char *out, size_t out_sz) that finds the header name (case-insensitive) and writes its trimmed value to out.
response: a NUL-terminated HTTP response (status line, CRLF-separated headers, a blank line, then the body). The grader passes a fixed string.name: the header name to look up (matched case-insensitively).out, out_sz: the output buffer and its capacity.Returns int: 0 if the header exists (writing its trimmed value to out), -1 otherwise.
find_header(resp, "Server", out, sz) -> 0, out = "nginx"
find_header(resp, "content-length", out, sz) -> 0, out = "42" (case-insensitive)
find_header(resp, "X-Missing", out, sz) -> -1
strncasecmp).A NUL-terminated HTTP response, a header name, and an output buffer with its size.
An int: 0 with the trimmed value in out if found, else -1.
Case-insensitive name match; trim the value; stop at the blank line.
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stddef.h>
int find_header(const char *response, const char *name, char *out, size_t out_sz) {
/* TODO */
return -1;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.