feat: inching our way towards http routing
This commit is contained in:
parent
5dc772e507
commit
6d4b94c55e
8 changed files with 126 additions and 135 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
5
src/http/http_route.c
Normal file
5
src/http/http_route.c
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
#include "event_loop.h"
|
||||
|
||||
typedef void (*routing_func)(event_loop_conn *);
|
||||
|
||||
routing_func http_route();
|
||||
Loading…
Add table
Add a link
Reference in a new issue