25 lines
723 B
C
25 lines
723 B
C
#include "http.h"
|
|
#include "picohttpparser.h"
|
|
|
|
/*
|
|
* given the HTTP path, parse the request
|
|
*/
|
|
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
|
|
size_t num_headers = HTTP_MAX_ALLOWED_HEADERS;
|
|
|
|
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 == -1) {
|
|
return http_parse_error_invalid;
|
|
} else if (res == -2) {
|
|
return http_parse_error_incomplete;
|
|
}
|
|
|
|
req->len = res;
|
|
|
|
return http_parse_error_ok;
|
|
}
|