networking · intermediate · ~15 min

Parse the request line

Split an HTTP request line into fields.

Challenge

Implement int parse_request_line(const char *line, char *method, int msz, char *path, int psz) splitting METHOD SP PATH SP VERSION into method and path. Return 1 on success, 0 if it doesn't have two spaces.

Starter code

#include <string.h>

int parse_request_line(const char *line, char *method, int msz, char *path, int psz) {
    /* TODO */
    return 0;
}

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