networking · intermediate · ~15 min

Build an HTTP GET request

Construct a valid HTTP request line + Host header.

Challenge

Implement int build_get(char *out, int outsz, const char *host, const char *path) writing a minimal HTTP/1.1 GET request: GET <path> HTTP/1.1\r\nHost: <host>\r\n\r\n. Return the length.

Starter code

#include <stdio.h>

int build_get(char *out, int outsz, const char *host, const char *path) {
    /* TODO */
    return 0;
}

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