postnummer-app/backend/http.c

27 lines
614 B
C
Raw Normal View History

2023-02-09 12:50:26 +00:00
#include "http.h"
#include <stdlib.h>
HttpRequestHeader parse_http_request_header(const char* message, size_t message_size)
{
size_t i = 0;
// parse method
HttpMethod method;
if (i + 3 < message_size && strncmp(&message[0], "GET", 3)) {
method = HttpMethodGet;
i += 3;
} else if (i + 4 < message_size && strncmp(&message[0], "POST", 4)) {
method = HttpMethodPost;
i += 4;
} else {
printf("error: header parse fail #1\n");
exit(1);
}
// skip space
i += 1;
if (i >= message_size) { }
return (HttpRequestHeader) { 0 };
}