add custom return codes

This commit is contained in:
2025-08-02 14:09:13 +02:00
parent 2918aeadcb
commit f0abac8be7
4 changed files with 112 additions and 89 deletions

View File

@@ -4,12 +4,9 @@
#include <stddef.h>
#include "myclib/hashmap/myhashmap.h"
#include "myclib/string/mystring.h"
#include "utils/config.h"
#define CWS_HTTP_LOCATION_LEN 512
#define CWS_HTTP_LOCATION_PATH_LEN 1024
#define CWS_HTTP_VERSION_LEN 8
typedef enum cws_http_method_t {
CWS_HTTP_GET, /**< GET method */
CWS_HTTP_POST, /**< POST method */
@@ -29,16 +26,13 @@ typedef enum cws_http_status_t {
*
*/
typedef struct cws_http_t {
int sockfd; /**< Socket file descriptor */
cws_http_method method; /**< HTTP request method */
char location[CWS_HTTP_LOCATION_LEN]; /**< Resource requested */
char location_path[CWS_HTTP_LOCATION_PATH_LEN]; /**< Full resource path */
char http_version[CWS_HTTP_VERSION_LEN]; /**< HTTP version */
mcl_hashmap *headers; /**< Headers hash map */
int sockfd; /**< Socket file descriptor */
cws_http_method method; /**< HTTP request method */
mcl_string *location; /**< Resource requested */
mcl_string *location_path; /**< Full resource path */
mcl_string *http_version; /**< HTTP version */
mcl_hashmap *headers; /**< Headers hash map */
} cws_http;
/* Connection */
/* Accept-Encoding */
/* Accept-Language */
/**
* @brief Parses a HTTP request
@@ -48,9 +42,7 @@ typedef struct cws_http_t {
*/
cws_http *cws_http_parse(char *request_str, int sockfd, cws_config *config);
int cws_http_parse_method(cws_http *request, const char *method);
int cws_http_get_content_type(cws_http *request, char *content_type);
char *cws_http_status_string(cws_http_status status);
/**
* @brief Build the http response
@@ -66,4 +58,4 @@ void cws_http_send_simple_html(cws_http *request, cws_http_status status, char *
void cws_http_free(cws_http *request);
#endif
#endif