#ifndef INCLUDED_HTTP_H #define INCLUDED_HTTP_H #include #include typedef struct _HTTPHeaderList HTTPHeaderList; struct _HTTPHeaderList { char *key; size_t key_length; char *value; size_t value_length; HTTPHeaderList *next; }; HTTPHeaderList *http_header_list_push(HTTPHeaderList *list, const char *key, const char *value); void free_http_header_list(HTTPHeaderList *list); const char *http_header_list_search(HTTPHeaderList *list, const char *key, const char *def); typedef enum { HRPR_OK, HRPR_NO_MEM, HRPR_BAD_VERSION, HRPR_BAD_FORMAT, HRPR_READ_FAILED, } HTTPRequestParseResult; typedef struct { const char *method; const char *uri; // relative (shares memory with uri) const char *path; HTTPHeaderList *headers; } HTTPRequest; HTTPRequestParseResult parse_http_request(FILE *stream, HTTPRequest *restrict out); void free_http_request(HTTPRequest *restrict req); typedef struct { int status; HTTPHeaderList *headers; size_t body_length; } HTTPResponse; const char *status_code_to_message(int status, size_t *restrict length); void format_http_response(FILE *stream, HTTPResponse *restrict resp); #endif