59 lines
1.3 KiB
C
59 lines
1.3 KiB
C
#ifndef HTTP
|
|
#define HTTP
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "picohttpparser.h"
|
|
|
|
#include "event_loop.h"
|
|
|
|
#define HTTP_MAX_ALLOWED_HEADERS 8
|
|
|
|
extern const char http_404[];
|
|
extern const size_t http_404_len;
|
|
extern const char http_405[];
|
|
extern const size_t http_405_len;
|
|
extern const char http_500[];
|
|
extern const size_t http_500_len;
|
|
|
|
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;
|
|
const char *query;
|
|
size_t query_len;
|
|
struct phr_header headers[HTTP_MAX_ALLOWED_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;
|
|
|
|
/* void http_route(event_loop_conn *conn); */
|
|
|
|
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);
|
|
|
|
#endif
|