networking · beginner · ~15 min
Validate against the common HTTP methods.
Check whether a string is one of the common HTTP methods a server accepts.
Implement int is_http_method(const char *m).
m: a NUL-terminated candidate method string.Return 1 if m is exactly one of GET, POST, PUT, DELETE, or HEAD (case-sensitive), else 0.
is_http_method("GET") -> 1
is_http_method("POST") -> 1
is_http_method("FETCH") -> 0
m: a NUL-terminated candidate method string.
1 if m is one of GET, POST, PUT, DELETE, HEAD; else 0.
Exact, case-sensitive match against the five-method set.
#include <string.h>
int is_http_method(const char *m) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.