lander/include/http/req.h

47 lines
959 B
C
Raw Normal View History

#ifndef LANDER_HTTP_REQ
#define LANDER_HTTP_REQ
#include <regex.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include "http/types.h"
#include "picohttpparser.h"
#define HTTP_MAX_ALLOWED_HEADERS 16
#define HTTP_MAX_REGEX_GROUPS 4
/*
* Struct representing the specific type of request
*/
typedef struct http_request {
size_t len;
int minor_version;
http_method method;
const char *path;
size_t path_len;
const char *query;
size_t query_len;
http_body_type body_type;
union {
char *buf;
FILE *file;
} body;
size_t body_len;
size_t body_received;
char *body_file_name;
regmatch_t regex_groups[HTTP_MAX_REGEX_GROUPS];
struct phr_header headers[HTTP_MAX_ALLOWED_HEADERS];
size_t num_headers;
} http_request;
typedef enum http_parse_error {
http_parse_error_ok = 0,
http_parse_error_incomplete = 1,
http_parse_error_invalid = 2,
http_parse_error_unknown_method = 3
} http_parse_error;
#endif