lander/include/http.h

59 lines
1.3 KiB
C
Raw Normal View History

2023-05-25 12:01:20 +02:00
#ifndef HTTP
#define HTTP
#include <stdlib.h>
#include "picohttpparser.h"
#include "event_loop.h"
2023-05-27 15:38:06 +02:00
#define HTTP_MAX_ALLOWED_HEADERS 8
2023-05-25 12:01:20 +02:00
extern const char http_404[];
extern const size_t http_404_len;
2023-05-26 22:41:01 +02:00
extern const char http_405[];
extern const size_t http_405_len;
2023-05-25 12:01:20 +02:00
extern const char http_500[];
extern const size_t http_500_len;
2023-05-27 15:38:06 +02:00
typedef enum http_request_method {
http_request_method_get = 0,
http_request_method_post = 1,
http_request_method_put = 2,
http_request_method_patch = 3,
http_request_method_delete = 4
} http_request_method;
/*
* Struct representing the specific type of request
*/
typedef struct http_request {
size_t len;
int minor_version;
const char *method;
size_t method_len;
const char *path;
size_t path_len;
2023-05-27 17:14:49 +02:00
const char *query;
size_t query_len;
2023-05-27 15:38:06 +02:00
struct phr_header headers[HTTP_MAX_ALLOWED_HEADERS];
} http_request;
2023-05-25 12:01:20 +02:00
typedef enum http_parse_error {
http_parse_error_ok = 0,
http_parse_error_incomplete = 1,
http_parse_error_invalid = 2,
} http_parse_error;
2023-05-27 15:38:06 +02:00
/* void http_route(event_loop_conn *conn); */
2023-05-26 22:41:01 +02:00
typedef enum http_response_type {
http_not_found = 404,
http_method_not_allowed = 405
} http_response_type;
void http_write_standard_response(event_loop_conn *conn,
http_response_type type);
2023-05-25 12:01:20 +02:00
#endif