feat: inching our way towards http routing

This commit is contained in:
Jef Roosens 2023-05-25 22:58:00 +02:00 committed by Chewing_Bever
parent 5dc772e507
commit 6d4b94c55e
Signed by: Jef Roosens
GPG key ID: B75D4F293C7052DB
8 changed files with 126 additions and 135 deletions

View file

@ -7,25 +7,19 @@
http_parse_error http_parse_request(http_request *req, const char *buf,
size_t buf_size) {
// First we try to parse the incoming HTTP request
const char *method, *path;
struct phr_header headers[16];
size_t method_len, path_len, num_headers;
int minor_version;
size_t num_headers = HTTP_MAX_ALLOWED_HEADERS;
int res =
phr_parse_request(buf, buf_size, &method, &method_len, &path, &path_len,
&minor_version, headers, &num_headers, 0);
int res = phr_parse_request(buf, buf_size, &req->method, &req->method_len,
&req->path, &req->path_len, &req->minor_version,
req->headers, &num_headers, 0);
if (res == -2) {
if (res == -1) {
return http_parse_error_invalid;
} else if (res == -2) {
return http_parse_error_incomplete;
} else if (res < 0) {
return http_parse_error_invalid;
}
// Next, we parse the HTTP request as a lander-specific request
if (path_len == 0 || path[0] != '/') {
return http_parse_error_invalid;
}
req->len = res;
return http_parse_error_ok;
}