httpd/httpd/src/http/http.h

80 lines
1.5 KiB
C
Raw Normal View History

#ifndef HTTP_H
#define HTTP_H
#include "../utils/string/string.h"
// === Enums
enum http_method
{
GET,
POST,
PUT,
DELETE,
// PATCH,
// HEAD,
// OPTIONS,
// CONNECT,
// TRACE
};
// === Structures
struct http_header
{
struct string *field;
struct string *value;
struct http_header *next;
};
struct http_request
{
enum http_method method;
struct string *path;
struct string *protocol;
struct string *protocol_version;
struct http_header *headers; // Headers linked list
};
struct http_response
{
struct string *protocol;
struct string *protocol_version;
int status_code;
struct string *status_msg;
struct http_header *headers; // Headers linked list
};
// === Functions
/* @brief Parses the HTTP request and splits it into a request structure
*
* @params req
*
* @return A pointer to the structure containing the request infos on success,
* NULL otherwise
*/
struct http_request* parse_request(struct string* req);
/* @brief Generates a response to the given request
*
* @params req
*
* @return A pointer to the generated response struct on success,
* NULL otherwise
*/
struct http_response* generate_response(struct http_request* req);
/* @brief Formats the given response structure into a valid HTTP response
* string
*
* @params resp
*
* @return A pointer to the string containing the response on success,
* NULL otherwise
*/
struct string* format_response(struct http_response* resp);
#endif // ! HTTP_H