27 lines
614 B
C
27 lines
614 B
C
#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 };
|
|
}
|